Redis Key expire notification with Jedis not working

2.2k views Asked by At

I am using Jedis 2.9.0 version and i followed

Redis Key expire notification with Jedis

but onPMessage method in Listener is not called when redis key expires.

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.

1

There are 1 answers

2
Matías Fidemraizer On BEST ANSWER

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.

Some docs page will explain you how to enable them.