Subscribe to keys update

22 views
Skip to first unread message

Arnaud Tanguy

unread,
Feb 9, 2012, 4:31:11 AM2/9/12
to redi...@googlegroups.com
Hi guys,

I'm wondering if there is a simple way to receive notification when a counter on a key is updated (via INCR or DECR).
I don't think that Redis can push the value of a counter directly to clients.
That's why, I'm thinking about publishing a notification on a channel (the channel is the key name) so clients will receive a notification and query Redis to get the value.

Is that the right way to do it?

Thanks for your feedback.

Arnaud.

Dvir Volk

unread,
Feb 9, 2012, 1:29:06 PM2/9/12
to redi...@googlegroups.com
yes this is definitely the way to go.



Arnaud.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To view this discussion on the web visit https://groups.google.com/d/msg/redis-db/-/DX8d-IqR4RUJ.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.



--
Dvir Volk
System Architect, The Everything Project (formerly DoAT)

Josiah Carlson

unread,
Feb 9, 2012, 1:52:41 PM2/9/12
to redi...@googlegroups.com
On Thu, Feb 9, 2012 at 1:31 AM, Arnaud Tanguy <arnaud...@gmail.com> wrote:
> Hi guys,
>
> I'm wondering if there is a simple way to receive notification when a
> counter on a key is updated (via INCR or DECR).

There is no current way, but at least one request for notifications.

> I don't think that Redis can push the value of a counter directly to
> clients.
> That's why, I'm thinking about publishing a notification on a channel (the
> channel is the key name) so clients will receive a notification and query
> Redis to get the value.
>
> Is that the right way to do it?

That will work. Alternatively, if you want to go a bit over the top,
you could use MONITOR and build a system that automatically broadcasts
updates when certain operations are performed. With such a system, any
client that is updating data doesn't need to be updated to also
publish information.

Here's a quick hack that will publish the name of a key being
incremented to a channel of the same name for INCR operations.
redis-cli monitor | sed -e 's/"//g;s/(db ..*)//g' | grep INCR | awk
'{print "publish", $3, $3}' | redis-cli

It doesn't really support multiple databases, as it discards database
information and posts publish information into DB 0, but adding that
functionality shouldn't be that bad.

Regards,
- Josiah

Reply all
Reply to author
Forward
0 new messages