Introduction
EXPIRE and TTL help you control how long data stays in Redis before it is automatically removed. This keeps your database clean and saves space.
EXPIRE key seconds TTL key
EXPIRE session123 1800TTL session123
EXPIRE tempKey 60TTL tempKey
SET mykey "hello" EXPIRE mykey 10 TTL mykey
EXPIRE key 60 do?EXPIRE key 60 sets the key to expire after 60 seconds.session in Redis?TTL key.session, the correct command is TTL session.SET temp "data" EXPIRE temp 10 TTL temp
TTL temp command return immediately after setting the expire?temp is set with value "data" and an expire time of 10 seconds.SET user "Alice" EXPIRE user -5 TTL user
TTL user and why?cache with a value and ensure it expires in 30 seconds only if it does not already have an expiration. Which Redis command sequence achieves this safely?Pass the test and this pattern moves unknown