0

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 
chiwangc
  • 3,566
  • 16
  • 26
  • 32

1 Answers1

4

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

Community
  • 1
  • 1
Itamar Haber
  • 47,336
  • 7
  • 91
  • 117