跳到主要内容
CNode

redis里怎样设置过期时间

问答
Wwuyanwen发布于 10 年前最后回复 10 年前
3111630

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)

Q
qingmingsang#310 年前

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

Y
yjhjstz#210 年前

可以去提交 Issue 了。

I
im-here#110 年前

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

参与回复

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