Can you expire a key value pair for a hashKey in Redis

旧城冷巷雨未停 提交于 2019-12-13 07:43:20

问题


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 

回答1:


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



来源:https://stackoverflow.com/questions/29959356/can-you-expire-a-key-value-pair-for-a-hashkey-in-redis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!