CNode

node.js 使用redis做监听过期事件遇到的问题

问答
CCarl-piao发布于8 年前最后回复8 年前2 回复4306 浏览0 收藏

设置的key过期以后用redis.psubscribe()是可以监听到过期的key,问题是会重复的监听到相同的key,怎么才能不重复呢 图片.png 如这图片的显示来说,我用set(key, value, 10, "EX", redis.print)做了个过期处理,连续的向这个key提交了几次,然后等待过期。按照redis逻辑来说,该key过期只会监听到一次就够了,但是重复了

查看回复

回复 (2)

C
Carl-piao#1·8 年前

不是很明白这句话的意思,至于升级是升级redis的版本吗,redis的版本是比较新的版本

P
papandadj#2·8 年前

Tells Redis to delete the key after ttl seconds. If we are using Redis < 2.1.3 and if a ttl was already set with another prior client.expire invocation, then the new ttl does NOT override the old ttl. If we are using Redis >= 2.1.3 and if a ttl was already set with another prior client.expire invocation, then the new ttl DOES override the old ttl. The expiry can be removed from the key if the key is set to a new value using the client.set(key, value) command or when a key is destroyed via the client.del(key) command. Passes 1 to callback if key has no current ttl expiry. Passes 0 to callback if key does not exist or if we are using Redis < 2.1.3, and key already has a current ttl expiry. 升级就好了

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