pub/sub, where is the callback?

653 views
Skip to first unread message

S Ahmed

unread,
Mar 4, 2011, 11:06:12 AM3/4/11
to redi...@googlegroups.com
I read the pub/sub topic on redis.io (http://redis.io/topics/pubsub), but I am confused as to how this really works.

Scenerio of  a web application:

Say I have a key that stores a list of id's.
If this key ever gets updated, I want to notify all subscribers of this event, and for example purposes say this subscriber is going to make an update to something in mysql.

Doesn't there need to be a callback?  I don't see where I put my callback method when I subscribe?

Sorry I'm just a 'little' lost here! :)

Or is this something that the Ruby client will have in its API?


Example:  I have a friends list, a list of id's of all my friends.  There is a publisher that will notify all subscribers whenever a friend logs into the website, and the subscribers will insert a row in a database whenever a friend logs into the website.  Is this something Redis could help with?  I am just confused as to how this would work without a callback?


Josiah Carlson

unread,
Mar 4, 2011, 2:05:15 PM3/4/11
to redi...@googlegroups.com, S Ahmed
You connect to Redis, and your client subscribes to keys. While that
client is connected, it will receive any messages that have been
"publish"ed to those keys. It doesn't look for changes to those keys,
it looks for things that are explicitly published. There are no
callbacks.

- Josiah

> --
> You received this message because you are subscribed to the Google Groups
> "Redis DB" group.
> 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.
>

Salvatore Sanfilippo

unread,
Mar 4, 2011, 2:20:56 PM3/4/11
to redi...@googlegroups.com, Josiah Carlson, S Ahmed
Actually calling them keys may be confused Pub/Sub has nothing to do
with keys, but with channels.

Btw what you want is:

MULTI
LPUSH foo bar
PUBLISH foo modified
EXEC

or something along this lines.
Alternatively you could push a list of changes against a list, if your
work flow is in the "workers" style.

Cheers,
Salvatore

--
Salvatore 'antirez' Sanfilippo
open source developer - VMware

http://invece.org
"We are what we repeatedly do. Excellence, therefore, is not an act,
but a habit." -- Aristotele

Aykut Kadayıfçı

unread,
Dec 20, 2015, 5:37:06 AM12/20/15
to Redis DB, josiah....@gmail.com, sahme...@gmail.com
Hello all;

I would like to get an expert's idea for an implementation problem that i am dealing with right now. I'd like to create a system that whenever something is written on a Master node by any client, I'd like to push the updated data to the all clients that are connected to our redis cloud.

Can i use this subscription system to implement such a kind of a system ? (Basically i'm going to send a serialized struct data with hiredis to the master node then i'll push this data to the clients)

Thanks in advance.
Reply all
Reply to author
Forward
0 new messages