Reputation:
An HSET is like so:
HSET myhash field1 "Hello"
is there a way to put an expiration/TTL on the "field1" key. It's trivial to put an expiration on myhash tmk, but I don't know how to put a TTL on key of a hash.
https://redis.io/commands/expire
Otherwise, I am stuck using:
SET field1 "Hello"
EXPIRE field1 10
and putting all my keys at the top-level instead of a hash :(
Upvotes: 5
Views: 9292
Reputation: 1039
Since Redis Community Edition 7.4, you can expire individual fields in a hash.
This command sets TTL of 3600 seconds on fields field1
, field2
, and field3
of hash hashkey
.
HEXPIRE hashkey 3600 FIELDS 3 field1 field2 field3
This command sets expiry at unixtime 1735373125 (in seconds) on fields field1
and field2
of hash hashkey
.
HEXPIREAT hashkey 1735373125 FIELDS 2 field1 field2
See this doc for more details.
Upvotes: 0
Reputation: 10015
See https://github.com/antirez/redis/issues/1042
Currently it's not possible.
Upvotes: 1