TTL and Expiry
Set a lifetime
TTL is time to live in seconds. Expired keys disappear automatically.
SET session:abc "data" EX 3600
TTL session:abc
EXPIRE cache:home 60
Persist forever again
Remove an expiry with PERSIST when you need the key to stay.
PERSIST session:abc
TTL session:abc
Millisecond precision
PEXPIRE/PTTL use milliseconds when you need finer control.
SET lock:1 "1" PX 500
PTTL lock:1
Design with expiry
Caches and sessions should almost always expire. Missing TTLs are a common cause of Redis memory growth.
Comments
One comment per signed-in account. Comments are saved with this page’s URL.