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.
|