CNode

redis里怎样设置过期时间

问答
Wwuyanwen发布于10 年前最后回复10 年前3 回复11129 浏览0 收藏

var redis =require('redis'); var client=redis.createClient(6379,'localhost'); client.rpush("testLists",JSON.stringify({pid:123812,date:4567})); client.rpush("testLists",JSON.stringify({pid:1235,date:4563})); client.rpush("testLists",JSON.stringify({pid:1238,date:4561})); client.lrange("testLists",0,-1,function(err,lists){ console.log(lists); });

比如以上代码,我想把其中的一条数据client.rpush("testLists",JSON.stringify({pid:123812,date:4567}));设置成过期了,怎么设置,求大神帮忙!现在只会 client.expire('testLists', 30);但这样的话,30秒后3条数据都没了,我想把其中一条没了,怎么弄。

查看回复

回复 (3)

I
im-here#1·10 年前

expire 是针对key的,你说的这个需求估计实现不了。

Y
yjhjstz#2·10 年前

可以去提交 Issue 了。

Q
qingmingsang#3·10 年前

你这里写的过期操作是针对key的,你这里就一个key,过期了数据当然都没了

参与回复
登录后即可参与回复。登录