Key expiration listener

457 views
Skip to first unread message

Dileep Mandapam

unread,
Mar 3, 2014, 8:54:53 AM3/3/14
to jedis...@googlegroups.com
Hi All,

I want to subscribe for only key expired events Please help me .

//Keys 
                        jedis.set(element,String.valueOf(timeInSeconds));
jedis.expire(element, timeInSeconds);
jedis.subscribe(KeyExpiredListener.INSTANCE, "*");;  //what should be the channel name ???



//Listener

private static class KeyExpiredListener extends JedisPubSub{
public static final KeyExpiredListener INSTANCE = new KeyExpiredListener();

public void onMessage(String channel, String message) {
CLEAN_UP_LOGGER.info("onMessage channel = {} message = {} ",channel,message);
        }

        public void onSubscribe(String channel, int subscribedChannels) {
        CLEAN_UP_LOGGER.info("onSubscribe channel = {} subscribedChannels = {} ",channel,subscribedChannels);
        }

        public void onUnsubscribe(String channel, int subscribedChannels) {
        CLEAN_UP_LOGGER.info("onSubscribe channel = {} subscribedChannels = {} ",channel,subscribedChannels);
        }

        public void onPSubscribe(String pattern, int subscribedChannels) {
        CLEAN_UP_LOGGER.info("onSubscribe pattern = {} subscribedChannels = {} ",pattern,subscribedChannels);
        }

        public void onPUnsubscribe(String pattern, int subscribedChannels) {
        CLEAN_UP_LOGGER.info("onPUnsubscribe pattern = {} subscribedChannels = {} ",pattern,subscribedChannels);
        }

        public void onPMessage(String pattern, String channel,
            String message) {
        CLEAN_UP_LOGGER.info("onPMessage pattern = {} channel = {}  message = {} ",pattern,channel,message);
        }
}

Thanks
Dileep.

임정택

unread,
Mar 3, 2014, 6:25:51 PM3/3/14
to jedis...@googlegroups.com
Hello!


Briefly, you cannot subscribe only key expired events, but with key deletion events.
(Redis treats key expired to same as delete.)
And also, Redis key expiring is not occurring on time key's TTL reaches to 0.
(See http://redis.io/commands/expire -> How Redis expires key)

Hope this helps.

Sincerely.
Jungtaek Lim (HeartSaVioR)

2014년 3월 3일 월요일 오후 10시 54분 53초 UTC+9, Dileep Mandapam 님의 말:
Reply all
Reply to author
Forward
0 new messages