I understand that expiring values is possible using normal redis string, but how about redis hash? For example, I need to expire keys that are older than a week.
@harry
you can set expiry to any Redis data types keys. below is example for Hashes
redis> HSET myhash field1 "helloworld"
(integer) 0
redis> EXPIRE myhash 60
(integer) 1
redis> TTL myhash
(integer) 51
redis> HGET myhash field1
"helloworld"
redis> TTL myhash
(integer) 10
redis> TTL myhash
(integer) -2
redis> HGET myhash field1
(nil)
Hope this helps.
1 Like
Hey @harry
remember that all redis key have the string data type, this means that regardless of the type of data that a key in redis holds (in your case a hash) because the key itself is a string, its expiration time can be specified just like you noted.