Hello, I would like to know if it's possible to set a expire time on keys of a hash ? For example, i would like to have the list of connected members in a hash with an expiration of 5 minutes on each key.
Is it possible?
Thanks, and sorry in advance for my english.
Regards, Max
Comment From: antirez
Hi, it is not possible, either use a different top-level key for that specific field, or store along with the filed another field with an expire time, fetch both, and let the application understand if it is still valid or not based on current time.
Comment From: wheelq
redis 127.0.0.1:6379> hset expire:me name tom (integer) 0 redis 127.0.0.1:6379> hget expire:me name "tom"
redis 127.0.0.1:6379> expire expire:me 10 (integer) 1 redis 127.0.0.1:6379> ttl expire:me (integer) 8
... ... ...
redis 127.0.0.1:6379> ttl expire:me (integer) -1 redis 127.0.0.1:6379> hget expire:me name (nil)
so it works
Comment From: nirvdrum
I believe the request is to expire individual fields. Expiring the entire hash is the same as expiring any other key.
Comment From: dengchunping
Yes, I've also met this requirement. Is it possible to expire individual fields?
Comment From: jbergstroem
Is there a specific problem with creating multiple hashes with different expiration times?
Comment From: nirvdrum
Well, I almost never want to expire an entire hash at once. So really, you're suggesting breaking up a hash into a bunch of keys. That works, but the same argument could be used to ask why you need a hash at all? There's immense value in grouping all your logically related keys together. Otherwise, you need to do that accounting through some set that stores your keys and you run into referential integrity issues. It's all doable, but it feels like a pretty big omission in redis to not support expiring individual keys in a hash. And I'm not convinced there's any value in having N different people solve it M different ways.
Comment From: dengchunping
Thanks Kevin Menard & Johan Bergström. Actually I met the same scenario described here:https://github.com/antirez/redis/issues/242, and I have read comments given by Salvatore. If I split all the fields to keys like this: hashkey:field1, hashkey:field2,.. It is difficult to manage these keys as a collection. such as querying all the fields, KEYS 'patten' is required...
Regards, Dengchunping
Comment From: bjoshuanoah
This is very problematic. The reason I want to expire specific keys inside a hash is because I'm storing cached settings in the hash. I want to expire the keys automatically after I set them. at the same time, I need to be able to kill the whole hash if all of my settings have been updated. So I need the ability to get these settings in the list, and kill the list. without finding all instance of settings:whatever.
Comment From: tuphamphuong
Have same problem with bjoshuanoah, now, i am using key with ttl instead of hash, e.g: Hash: Hashname A - Key B - Value C Key-Value: Key A_B - Value C
Comment From: scaryguy
Is lack of this feature technically not possible or is it choice of design?
Comment From: badboy
The choice of design lead to an implementation that doesn't allow an implementation.
Comment From: pensierinmusica
https://github.com/antirez/redis/issues/1042#issuecomment-143109286
Comment From: jakejgordon
:+1:
Comment From: iceelee
redis itself does not support , this function is too useful.
Comment From: nomi-ramzan
Until today redis did not plan to implement this functionality :-(
Comment From: oylz
redis 127.0.0.1:6379> hset expire:me name tom (integer) 0 redis 127.0.0.1:6379> hget expire:me name "tom"
redis 127.0.0.1:6379> expire expire:me 10 (integer) 1 redis 127.0.0.1:6379> ttl expire:me (integer) 8
... ... ...
redis 127.0.0.1:6379> ttl expire:me (integer) -1 redis 127.0.0.1:6379> hget expire:me name (nil)
so it works
there is only one field in the hashtable, what about multiple fieleds? It would not work correly!
Comment From: itamarhaber
@oylz - I believe that the original intent of this feature request is allowing the expiry of specific fields inside the hash, not the entire key.
Comment From: oylz
@itamarhaber how aboule like this?: hset expire:me name1 tom1 hset expire:me name2 tom2 hset expire:me name3 tom3
ttl expire:me 10
The entire hashtable(expire:me) will be expired.
Comment From: nomi-ramzan
@oylz We know complete hash will be expire. its working but here we are talking about one single field of any hash (as @itamarhaber explained you already). e.g In your case how can you expire name1 field after 5s, name2 after 10 and name 3 after 15 seconds ? I hope now its clear what use-case is under discussion here.
Comment From: oylz
@nomi-ramzan do you really understand? as @itamarhaber said:" I believe that the original intent of this feature request is allowing the expiry of specific fields inside the hash, not the entire key."
Comment From: oylz
@nomi-ramzan sorry, I replied to you wrong at the begin, I should reply @wheelq . e.g: _redis 127.0.0.1:6379> hset expire:me name tom (integer) 0 redis 127.0.0.1:6379> hget expire:me name "tom"
redis 127.0.0.1:6379> expire expire:me 10 (integer) 1 redis 127.0.0.1:6379> ttl expire:me (integer) 8
... ... ...
redis 127.0.0.1:6379> ttl expire:me (integer) -1 redis 127.0.0.1:6379> hget expire:me name (nil)
so it works_
Comment From: wincodes
This is 2020, Redis should look in to this
Comment From: xiaozhitaba
our Company has implement expire hash field function it base redis 4.0
Comment From: anantharaman93
Providing this feature natively will be very much helpful. Thanks.
Comment From: JianyangZhang
I'm still waiting for this
Comment From: chenxuzhen
unbelievable! Redis still hasn't implemented it!
Comment From: niwinz
the same here, would be awesome to have the ability to set expire to hash fields
Comment From: Mont4
+1
Comment From: jasonzoujian
unbelievable! Redis still hasn't implemented it!
Comment From: Chickyky
+1 for this feature
Comment From: DobrovAlexey
Having discovered the Redis world, I imagined storing the cache in this form: 1) Each hash table - is my api method 2) Rows in hash tables - a hash function of the input parameters of the method and the value is the response of the method
Comment From: jitenshah18
+1 for this feature
Comment From: softlns
+1 for this feature
Comment From: mingrammer
+1
Comment From: darnfish
+1
Comment From: Alchemyhx
+1
Comment From: aditya-kapre-shrewsbury
+1
Comment From: aditya-kapre-shrewsbury
Is there specific reason expiring keys in hashes is not implemented ?
Comment From: itamarhaber
The reason this was never implemented yet is due to the increased complexity of time (CPU) and space (RAM) that this feature would require. That said, never say never.
Comment From: aditya-kapre-shrewsbury
Is time complexity going in the order of polynomial time ? What makes it RAM intensive though, cloning for any purpose?
Comment From: helderjbe
I'm sure if this feature was implemented redis would get a huge boost in popularity
Comment From: fanhualuo
+1 for this feature
Comment From: ClearLiF
+1
Comment From: WuZhiMing2
+1
Comment From: SmallOyster
+1 for this feature...... Also hope can set each fields' expire time not only one field.
Comment From: raniket
+1 for this feature.
Comment From: lhvubtqn
+1 for this feature.
Comment From: Chickyky
you guys can use my package support expire field/member in hash/set/sorted-set for work around
https://www.npmjs.com/package/redis-extend
Comment From: adimasuhid
+1 for this feature.
Comment From: chenyang8094
you guys can try this: https://github.com/alibaba/TairHash
Comment From: vijaybabu4589
+1
Comment From: universe111
+1
Comment From: pavanbhosle
+1, Very useful requirement this is. Please lets know if there is any latest release plan that supports it.
Comment From: CraigLager
+1
Comment From: triangle959
已收到
Comment From: jpsatterfield
Yes please = )
Comment From: easyu
This is a very nice feature, hope redis will implement it in the future
Comment From: gianielsevier
+1
Comment From: triangle959
已收到
Comment From: well-balanced
+1
Comment From: tauksun
this is still a issue, 11 years & counting +1
Comment From: triangle959
已收到
Comment From: aderevets-sift
+1
Comment From: mojirml
+1 for this feature
Comment From: triangle959
已收到
Comment From: BenNo1150
+1 please
Comment From: Harsh062
+1
Comment From: vedpd11
+1
Comment From: tillkruss
I'd love this +1
Comment From: triangle959
已收到
Comment From: meijie-jesse
+1
Comment From: Rush
I created a Redis module in Rust that implements an EXPIREMEMBER command https://github.com/Rush/redis_expiremember_module
It is not as sophisticated as the implementation in KeyDB but was designed for performance.
The only inconvenience is that client code should make sure to reset expirations by EXPIREMEMBER hash key 0 when deleting keys because the module doesn't have visibility into such operations and can't remove expirations by itself.
Comment From: moticless
Heads up, we've started implementing hash field expiration, and it's planned for an upcoming release.