RedisStore

518 views
Skip to first unread message

deakblue

unread,
Sep 24, 2011, 6:10:39 PM9/24/11
to Socket.IO
Two parts:

1. Do I tell socket.io to use redis somewhere? Is this a startup or
config thing because my understanding is that socket.io will either
use redis or an in memory store.

2. When using redis, I guess any other client of redis can publish to
the subscribed channels? If that's the case, holy cow that's
awesome. Is there any special notation on the names of socket.io
channels within redis or are they just as they are set in socket.io?

Thanks in advance, and huge props to an amazing framework,
-Will

deakblue

unread,
Sep 27, 2011, 2:48:52 PM9/27/11
to Socket.IO
I was able to get RedisStore running. I wasn't able to figure out
how to send messages along pub/sub channels created by socket but I
may try again using MONITOR to see what's going on inside the db.

Best regards,
-Will

Guillermo Rauch

unread,
Sep 27, 2011, 4:59:18 PM9/27/11
to sock...@googlegroups.com
Please keep in mind it's not public API yet, but will be very soon (possibly next week).
--
Guillermo Rauch
LearnBoost CTO
http://devthought.com

Daniel Shaw

unread,
Sep 27, 2011, 5:33:58 PM9/27/11
to sock...@googlegroups.com
RedisStore handles the interprocess communication (via Redis Pub/Sub)
for you. You really don't interact with these channels directly. All
you need to do is spin up `n` instances of your Socket.io server
running on different ports or servers pointing to the same Redis
server.

MONITOR is a good way to peak at what's going on under the hood if your curious.

Daniel Shaw
@dshaw


On Tue, Sep 27, 2011 at 11:48 AM, deakblue <will....@gmail.com> wrote:

Will Heger

unread,
Sep 27, 2011, 5:33:42 PM9/27/11
to sock...@googlegroups.com
Thanks for that, I wasn't sure if redis was prime-time yet.

I'm going to continue to manage my redis channels directly for now,
but I'll look out for the public api.

Thanks,
-Will

deakblue

unread,
Sep 27, 2011, 7:31:46 PM9/27/11
to Socket.IO

I grasp (I believe) how RedisStore is intended to support socket.io
servers.

But if the pub/sub channels are just vanilla redis pub/sub, any other
service could publish messages to socket.io clients without
necessarily knowing anything about socket.io. This could make for
some pretty sweet designs with loosely coupled services meeting around
Redis.

I'm currently just using the memory store and my clients subscribe to
Redis channels using a special 'subscribe' socket.io channel. It's
working great, but if it's all Redis, I could probably save a little
code.

Anyway, socket.io is great work, thanks,
-Will

Thomas Fritz

unread,
Oct 24, 2011, 10:14:50 AM10/24/11
to sock...@googlegroups.com
Hi

Is the RedisStore ready for use?
Guillermo, could you please explain a bit more how socket.io uses
redis. Which messages gets published, names, arguments? etc. etc.
Does socket.io also stores its "session" in redis then?
So when i do something like that:
<code>
socket.set('nickname', name, function () {
socket.emit('ready');
});
</code>

it gets saved in redis? If not that would be very great to share the state.


Kind regards

---
Thomas FRITZ
web http://fritzthomas.com
twitter http://twitter.com/thomasf

2011/9/28 deakblue <will....@gmail.com>:

Daniel Shaw

unread,
Oct 24, 2011, 1:34:45 PM10/24/11
to sock...@googlegroups.com
Thomas,

That's exactly right. I use Redis extensively in my apps and I've found that there's some key value data that works well associated directly with the socket like this, while other data (especially more complex data structures) is better stored directly in Redis using a separate RedisClient connection.

We'll get more documentation up on RedisStore when it's officially supported, but you're on the right track. 

Daniel Shaw
@dshaw

Thomas Fritz

unread,
Oct 25, 2011, 9:32:54 AM10/25/11
to sock...@googlegroups.com
Can you tell a bit more on the redis backend?
What about the events? Will they use redis pub/sub?

When do you think it will be released?

Kind regards

2011/10/24 Daniel Shaw <ds...@dshaw.com>:

dshaw

unread,
Oct 27, 2011, 9:02:32 PM10/27/11
to sock...@googlegroups.com
Events are distributed across nodes with Redis Pub/Sub. There's also a simple distributed storage mechanism which takes socket get/set and stores the data in Redis instead of in memory.

Here are a couple recent RedisStore sample apps from a talk I gave and a talk Arnout (3rd-Eden) gave.

Daniel Shaw
@dshaw

no1youknowz

unread,
Oct 30, 2011, 10:58:56 AM10/30/11
to Socket.IO
Does anyone know of any github repos that extensively work with redis?

I've seen this as a simplified example:
https://github.com/emrahayanoglu/Socket.io-Redis-RealTime-Chat-Example

But now I'm looking for ways to add to lists (store room names, users
to rooms) and to store the logs per room.

I can't seem to be able to add anything successfully to redis and then
get anything back, this is what I get from the console:
(error) ERR Operation against a key holding the wrong kind of value

Any help/advice welcome!

Cheers

no1youknowz

unread,
Oct 30, 2011, 1:22:39 PM10/30/11
to Socket.IO
After finding some good docs, I finally worked it out.

app.js : http://www.pastie.org/2783605
index.html : http://www.pastie.org/2783610

A bit buggy, but it's just to get some basic points nailed.

So I'm now confused about pub/sub.

I'm specifically looking at this example:
http://stackoverflow.com/questions/5739357/how-to-reuse-redis-connection-in-socket-io

I'm now unclear on how to handle multiple rooms and the pub/sub
model. Especially about getting all messages per room per user logged
into a db.

Cheers

dshaw

unread,
Oct 30, 2011, 11:29:48 PM10/30/11
to sock...@googlegroups.com
Use RedisStore instead of that hack. I've been considering whether to propose adding what you're trying to store to core. It would be convenient if you are using Redis persistance to be able to query Redis directly. I'm currently using a separate Redis client from what's used internally in RedisStore and persisting most of that information to either hashes ( http://redis.io/commands#hash ) or sets ( http://redis.io/commands#set ). Leave process dispatch and simple persistance to RedisStore.

Daniel Shaw
@dshaw

no1youknowz

unread,
Oct 31, 2011, 2:33:36 PM10/31/11
to Socket.IO
Ultimately what I am looking for are these:

1) Store rooms.
2) Store users in those rooms.
3) Store user sessions.

Redis Clustering.

Is there an ETA of when documentation regarding redisStore will be
available?

Reply all
Reply to author
Forward
0 new messages