Jedis 无法正常工作的 Redis 密钥过期通知
Redis Key expire notification with Jedis not working
我使用的是 Jedis 2.9.0 版本,我关注了
Redis Key expire notification with Jedis
但是在redis key过期的时候没有调用Listener中的onPMessage方法
在我使用的订阅者中
jedis.psubscribe(new KeyExpiredListener(), "*");
当我运行服务器
jedis.set("notify", "test");
jedis.expire("notify", 10);
但是 10 秒后 Redis 密钥过期但是 onPMessage 没有触发。
密钥空间过期通知不会仅在密钥过期时触发,但是(取自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.
此外,您可能还没有启用键空间通知:
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.
有些 docs page 会向您解释如何启用它们。
我使用的是 Jedis 2.9.0 版本,我关注了
Redis Key expire notification with Jedis
但是在redis key过期的时候没有调用Listener中的onPMessage方法
在我使用的订阅者中
jedis.psubscribe(new KeyExpiredListener(), "*");
当我运行服务器
jedis.set("notify", "test");
jedis.expire("notify", 10);
但是 10 秒后 Redis 密钥过期但是 onPMessage 没有触发。
密钥空间过期通知不会仅在密钥过期时触发,但是(取自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.
此外,您可能还没有启用键空间通知:
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.
有些 docs page 会向您解释如何启用它们。