Spring data redis - listen to expiration event -
i listen expiration events keyexpirationeventmessagelistener can't find example.
someone know how using spring boot 1.4.3 & spring data redis?
i doing
jedispool pool = new jedispool(new jedispoolconfig(), "localhost"); this.jedis = pool.getresource(); this.jedis.psubscribe(new jedispubsub() { @override public void onpmessage(string pattern, string channel, string message) { system.out.println("onpmessage pattern " + pattern + " " + channel + " " + message); list<object> txresults = redistemplate.execute(new sessioncallback<list<object>>() { public list<object> execute(redisoperations operations) throws dataaccessexception { operations.multi(); operations.opsforvalue().get("val:" + message); operations.delete("val:" + message); return operations.exec(); } }); system.out.println(txresults.get(0)); } }, "__keyevent@0__:expired");
and use spring instead of jedis directly.
regards
don't use keyexpirationeventmessagelistener
triggers rediskeyexpiredevent
leads failure in rediskeyvalueadapter.onapplicationevent
.
rather use redismessagelistenercontainer
:
@bean redismessagelistenercontainer keyexpirationlistenercontainer(redisconnectionfactory connectionfactory) { redismessagelistenercontainer listenercontainer = new redismessagelistenercontainer(); listenercontainer.setconnectionfactory(connectionfactory); listenercontainer.addmessagelistener((message, pattern) -> { // event handling comes here }, new patterntopic("__keyevent@*__:expired")); return listenercontainer; }
redismessagelistenercontainer
runs notifications on own thread.
Comments
Post a Comment