I am using Redis queue and adding the data using ListLeftPush and reading data using ListRightPop. It works fine I am able to get the data. But what if data has not popped out? Can we delete old data? or Can we add Value in Redis List with Expiration Time?
How to add time limit for each value while using ListLeftPush command in C#?
2
Answers
It is not possible to add expire time for individual value for the sake of keeping redis simple and fast.
you can only add expire time for individual keys i.e in ur case it is for whole list.
No redis doesn’t support that. Expiration is available only for the top level keys. The closes data type/solution for your case would be
sorted sets
.score
while adding to sorted set(ZADD
)LPOP
you useZPOPMAX
to get “to be last expired” element.ZREMRANGEBYSCORE
to remove expired elements.For the demonstration i used smaller numbers as expiration dates.