Expire key notification for specific key

569 views
Skip to first unread message

Hitesh Dobariya

unread,
Aug 7, 2014, 2:19:40 AM8/7/14
to redi...@googlegroups.com
Is there any option in redis to listen specific key like "user:*" ? i want to listen only expire event for specific key, not for other keys like "KEY1, KEY2" are expires. i tried with regex but it's not working for me..

Jan-Erik Rediger

unread,
Aug 7, 2014, 2:42:38 AM8/7/14
to redi...@googlegroups.com
I guess you're talking about keyspace notifications?
http://redis.io/topics/notifications

If so, Redis publishes commands for a specific key (mykey in this
example) to the channel: __keyspace@0__:mykey

If you you have keys like user:1, user:2 the channels will be:
__keyspace@0__:user:1
__keyspace@0__:user:2

You can subscribe to these using PSUBSCRIBE
http://redis.io/commands/psubscribe

PSUBSCRIBE __keyspace@0__:user:*

Make sure you enable the right keyspace notifications.
Does this help you?
> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
> To post to this group, send email to redi...@googlegroups.com.
> Visit this group at http://groups.google.com/group/redis-db.
> For more options, visit https://groups.google.com/d/optout.

Hitesh Dobariya

unread,
Aug 9, 2014, 3:05:50 AM8/9/14
to redi...@googlegroups.com, jan...@fnordig.de

rClient1.psubscribe('__keyevent@0__:expired'); 
rClient1.on("pmessage", function (channel, message) {
    c(message); // prints __keyevent@0__:expired
   c(channel); //prints __keyevent@0__:expired
}
,
so problem is i am unable to get key name which are going to expire. i want key name when it's expires. for example if user:123 is going expire then i am able to get user:123. so i can handle other my server event on it.

Hitesh Dobariya

unread,
Aug 9, 2014, 3:15:39 AM8/9/14
to redi...@googlegroups.com, jan...@fnordig.de
Thanks for your suggestion now i am able to get the notification.
Reply all
Reply to author
Forward
0 new messages