Reputation: 25914
I'd like to expires certain field of a hash after different amount of time. From the documentation it doesn't look to be possible: http://redis.io/commands/expire. Can I emulate this behavior somehow? Currently I'm just copying the hash name to be a prefix of all of its fields and adding expires to each. For the structure I'd like to store is:
"PEOPLE" : {
"NICK" : 29
"AMANDA" : 23
}
but I can't set an expire on "NICK", only on the whole hash "PEOPLE". So I convert it to and number of key, values:
"PEOPLE_NICK" : 29 (expire 2 hours)
"PEOPLE_AMANDA" 23 (expire 1 hour)
but there are many keys and it makes it very difficult to manage and more tedious to fetch as I have to fetch everything by the common prefix.
Upvotes: 2
Views: 2737
Reputation: 15773
If the above example is an accurate representation, and depending on how exactly you'll consume the data, you could use a sorted set with the score of each person be a Unix timestamp. Then you'd use zremrangebyscore on an Cron job to clean out items which are beyond you acceptable window.
Upvotes: 0