EXPIRE - Expire Key Value Pairs in Redis

Feature thumb redis course thumb

When you want to expire a key value pair set in the Redis database, you can use the EXPIRE command and pass it the number of seconds that for when you want it to expire.

redis> SET mykey "Hello"
"OK"
redis> EXPIRE mykey 10
(integer) 1
redis> TTL mykey
(integer) 10
redis> SET mykey "Hello World"
"OK"
redis> TTL mykey
(integer) -1
redis>