I am using Jedis 2.9.0 version and i followed
我正在使用Jedis 2.9.0版本,我跟着
Redis Key expire notification with Jedis
Redis Key使用Jedis过期通知
but onPMessage method in Listener is not called when redis key expires.
但是当redis键过期时,不会调用Listener中的onPMessage方法。
in Subscriber I used
在我使用的订阅者中
jedis.psubscribe(new KeyExpiredListener(), "*");
When I am running server
当我运行服务器时
jedis.set("notify", "test");
jedis.expire("notify", 10);
but After 10 seconds Redis key expired but onPMessage did not trigger.
但10秒后Redis键已过期,但onPMessage没有触发。
1 个解决方案
#1
2
Expire keyspace notification isn't fired just when a key has expired but (taken from the docs):
当密钥已过期但(从文档中取出)时,不会触发过期密钥空间通知:
- When the key is accessed by a command and is found to be expired.
当命令访问密钥并发现它已过期时。
- Via a background system that looks for expired keys in background, incrementally, in order to be able to also collect keys that are never accessed.
通过后台系统,在后台逐步查找过期的密钥,以便能够收集从未访问过的密钥。
In addition, maybe you've not enabled keyspace notifications:
此外,您可能没有启用密钥空间通知:
By default keyspace events notifications are disabled because while not very sensible the feature uses some CPU power. Notifications are enabled using the notify-keyspace-events of redis.conf or via the CONFIG SET.
默认情况下,禁用键空间事件通知,因为虽然不太明智,但该功能会使用一些CPU电源。使用redis.conf的notify-keyspace-events或CONFIG SET启用通知。
Some docs page will explain you how to enable them.
某些文档页面将向您解释如何启用它们。
#1
2
Expire keyspace notification isn't fired just when a key has expired but (taken from the docs):
当密钥已过期但(从文档中取出)时,不会触发过期密钥空间通知:
- When the key is accessed by a command and is found to be expired.
当命令访问密钥并发现它已过期时。
- Via a background system that looks for expired keys in background, incrementally, in order to be able to also collect keys that are never accessed.
通过后台系统,在后台逐步查找过期的密钥,以便能够收集从未访问过的密钥。
In addition, maybe you've not enabled keyspace notifications:
此外,您可能没有启用密钥空间通知:
By default keyspace events notifications are disabled because while not very sensible the feature uses some CPU power. Notifications are enabled using the notify-keyspace-events of redis.conf or via the CONFIG SET.
默认情况下,禁用键空间事件通知,因为虽然不太明智,但该功能会使用一些CPU电源。使用redis.conf的notify-keyspace-events或CONFIG SET启用通知。
Some docs page will explain you how to enable them.
某些文档页面将向您解释如何启用它们。