Reputation: 191
I've a use case where I need to store values for eg. SADD key *values
but I also want to persist the values only for certain duration say 1 day after which the specific value should get expired.
Please suggest how can this be achieved using redis.
Upvotes: 0
Views: 63
Reputation: 50112
Redis' expiration is implemented at key level, not inside the value. As an alternative, use a Sorted Set, with the score of each member being its expiration timestamp.
You will have to "expire" elements manually, so periodically call ZREMRANGEBYSCORE
to remove all elements with a timestamp lower than now.
Upvotes: 1