Redis: can an item in an array expire or a sorted set?

Currently, only the expiration of the entire key / value pair is possible? What should I do if I want to add values ​​to a list type structure and make them automatically be deleted 1 hour after insertion. Is this currently possible, or would you need to run a cron job to manually clean?

+86
caching redis
Sep 28 '11 at 3:18
source share
2 answers

Currently, only the expiration of an entire key / value pair is possible?

As far as I know, as well as according to the key commands and the expiration document, at present you can set the validity period only for a certain key, and not for the basic data structure. However, there is a discussion in google groups about this functionality with outlined alternative solutions.

+56
Sep 28 2018-11-11T00:
source share

There is a general scheme that can solve this problem quite well.

Use the sorted sets and use the timestamp as a count. Then it is trivial to delete elements according to the range of points that can be performed periodically or only with each record, while reading always ignoring elements outside the range, reading only the range of ratings.

More details here: https://groups.google.com/forum/#!topic/redis-db/rXXMCLNkNSs

+52
Nov 08 '13 at 11:41
source share



All Articles