The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

474834 (2) [Avatar] Offline
        elif conn.ttl(lockname) < 0:                    
            conn.expire(lockname, lock_timeout) 

It looks like the expiration time will be reset once the lock expires. If the process acquired the lock crashes, wouldn't these two lines make the lock live forever?
Can you explain in which situation we will need this piece of code and what's incorrect with my concern?
josiah.carlson (79) [Avatar] Offline
Your understanding of what is happening here is incorrect.

We set the expiration time on a key that does not have an expiration time, because that expiration was never set.

Keys that are expired are deleted and don't exist, so won't be inside that elif clause.

Note that this code and the book were written before you could pass both EX and NX to the SET command, which is why we use SETNX with a later EXPIRE.

If the book were to be written (or a new edition released) today, it would be a single SET call with both the EX and NX clauses, instead of these two steps/options/clauses.
474834 (2) [Avatar] Offline
Thanks! It helps a lot