redis里怎样设置过期时间
发布于 8 年前 作者 wuyanwen 10235 次浏览 来自 问答

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 回复

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

可以去提交 Issue 了。

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

回到顶部