Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Expire on hash #167

Closed
max13fr opened this issue Oct 28, 2011 · 73 comments
Closed

Implement Expire on hash #167

max13fr opened this issue Oct 28, 2011 · 73 comments

Comments

@max13fr
Copy link

max13fr commented Oct 28, 2011

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

@antirez
Copy link
Contributor

antirez commented Oct 28, 2011

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.

@antirez antirez closed this as completed Oct 28, 2011
@wheelq
Copy link

wheelq commented Mar 11, 2012

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

@nirvdrum
Copy link
Contributor

I believe the request is to expire individual fields. Expiring the entire hash is the same as expiring any other key.

@dengchunping
Copy link

Yes, I've also met this requirement. Is it possible to expire individual fields?

@jbergstroem
Copy link
Contributor

Is there a specific problem with creating multiple hashes with different expiration times?

@nirvdrum
Copy link
Contributor

nirvdrum commented Mar 5, 2013

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.

@dengchunping
Copy link

Thanks Kevin Menard & Johan Bergström. Actually I met the same scenario described here:#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

@bjoshuanoah
Copy link

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.

@tuphamphuong
Copy link

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

Hailei pushed a commit to Hailei/redis that referenced this issue Aug 29, 2014
Fix @see tags referencing int params that are now long
@scaryguy
Copy link

Is lack of this feature technically not possible or is it choice of design?

@badboy
Copy link
Contributor

badboy commented Mar 17, 2015

The choice of design lead to an implementation that doesn't allow an implementation.

@pensierinmusica
Copy link

#1042 (comment)

@jakejgordon
Copy link

👍

@iceelee
Copy link

iceelee commented Dec 29, 2016

redis itself does not support , this function is too useful.

@nomi-ramzan
Copy link

Until today redis did not plan to implement this functionality :-(

@oylz
Copy link

oylz commented Sep 30, 2018

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!

@itamarhaber
Copy link
Member

@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.

@oylz
Copy link

oylz commented Oct 8, 2018

@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.

@nomi-ramzan
Copy link

nomi-ramzan commented Oct 8, 2018

@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.

@oylz
Copy link

oylz commented Oct 8, 2018

@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."

@oylz
Copy link

oylz commented Oct 8, 2018

@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_

@wincodes
Copy link

wincodes commented Mar 19, 2020

This is 2020, Redis should look in to this

@xiaozhitaba
Copy link

our Company has implement expire hash field function
it base redis 4.0

@anantharaman93
Copy link

Providing this feature natively will be very much helpful.
Thanks.

@Chickyky
Copy link

Chickyky commented May 2, 2021

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

@adimasuhid
Copy link

+1 for this feature.

@chenyang8094
Copy link
Collaborator

you guys can try this: https://github.com/alibaba/TairHash

@vijaybabu4589
Copy link

+1

@universe111
Copy link

+1

@pavanbhosle
Copy link

+1, Very useful requirement this is. Please lets know if there is any latest release plan that supports it.

@CraigLager
Copy link

+1

@triangle959
Copy link

triangle959 commented Mar 3, 2022 via email

@jpsatterfield
Copy link

Yes please = )

@easyu
Copy link

easyu commented Mar 21, 2022

This is a very nice feature, hope redis will implement it in the future

@gianielsevier
Copy link

+1

@triangle959
Copy link

triangle959 commented Jul 12, 2022 via email

@well-balanced
Copy link

+1

@tauksun
Copy link

tauksun commented Sep 27, 2022

this is still a issue, 11 years & counting
+1

@triangle959
Copy link

triangle959 commented Sep 27, 2022 via email

@aderevets-sift
Copy link

+1

@mojirml
Copy link

mojirml commented Nov 7, 2022

+1 for this feature

@triangle959
Copy link

triangle959 commented Nov 7, 2022 via email

@BenNo1150
Copy link

+1 please

@Harsh062
Copy link

Harsh062 commented Dec 1, 2022

+1

1 similar comment
@vedpd11
Copy link

vedpd11 commented Dec 12, 2022

+1

@tillkruss
Copy link

I'd love this +1

@triangle959
Copy link

triangle959 commented Mar 13, 2023 via email

@meijie-jesse
Copy link

+1

@Rush
Copy link

Rush commented Jan 1, 2024

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.

@moticless
Copy link
Collaborator

Heads up, we've started implementing hash field expiration, and it's planned for an upcoming release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests