redisspring-webfluxreddison

how to configure the key expired event listener in redisson reactive api (spring boot project)


i am using spring boot web flux with redisson. I want to enable all key expired event in my application. i tried it this way. but it doesn't work.

this.client.getTopic("__keyevent@*__:expired", StringCodec.INSTANCE)
        .addListener(String.class, new MessageListener<String>() {
            @Override
            public void onMessage(CharSequence channel, String msg) {
                //
            }
        });

I wish a help to resole this problem.


Solution

  • 1st issue is, you haven't subscribed to the listener. and the 2nd one is that you can't use getTopic to the pub-sub event if you use a pattern in redisson. you should use getPatternTopic method like this. and make sure to subscribe to the process finally. and the listener should be implemented from PatternMessageListener interface.

    
            this.client
                    .getPatternTopic("__keyevent@*__:expired", StringCodec.INSTANCE)
                    .addListener(String.class, new PatternMessageListener<String>() {
                        @Override
                        public void onMessage(CharSequence pattern, CharSequence channel, String msg) {
                            System.out.println("pattern = " + pattern + ", channel = " + channel + ", msg = " + msg);
                        }
                    })
                    .subscribe();