APPENDIX · P5 · REDIS · FOR SLIDE 15
← Back to Slide 15
P5. TTL chain: SET, KEEPTTL, EXPIRE
SET lesson03:ttl:lecture v1 EX 300
TTL lesson03:ttl:lecture
SET lesson03:ttl:lecture v2
TTL lesson03:ttl:lecture
SET lesson03:ttl:lecture v3 KEEPTTL
TTL lesson03:ttl:lecture
EXPIRE lesson03:ttl:lecture 300
SET lesson03:ttl:lecture v4 KEEPTTL
TTL lesson03:ttl:lecture
TTL lesson03:nosuchkey
What the result should be
OK
(integer) 300 // ≈300
OK
(integer) -1 // SET removed the time limit
OK
(integer) -1 // KEEPTTL did not return
(integer) 1
OK
(integer) 300 // deadline saved
(integer) -2 // key does not exist
SET without EX
KEEPTTL
HSET and TTL
Disables TTL: the cache becomes "immortal."
It preserves the existing term but does not restore the one that was removed.
HSET preserves the key's expiration time but resets the TTL of the overwritten field (HEXPIRE — Redis 7.4).
Predict each TTL before launch. Expected: about 300, −1, −1, about 300. The exact seconds depend on the launch time.