Reputation: 1
I want to expire a particular key/value pair set in a hashKey in redis. But redis expires the whole hashKey with all keyValue pairs inside lost. For example i just want to remove Key:666 from seqNu. Using jedis.setex is other option but u cant set a hashKey in it.
jedis.hset("seqNu","666",System.currentTimeMillis()+"");
jedis.hset("seqNu","777",System.currentTimeMillis()+"");
jedis.expire("seqNu", 20); // This expires the whole HashKey: seqNu after 20 seconds
Upvotes: 0
Views: 7651
Reputation: 49942
Redis only expires "whole" keys, not individual elements inside its data structures (i.e.g. a Hash's field or a Set's member). Consider splitting your Hash into multiple string keys (each expirable by itself) or using Sorted Sets as explained here: Redis: To set timeout for a key value pair in Set
Upvotes: 4