OdieO
OdieO

Reputation: 7004

redisPub, redisSub, redisStore - for socket.io store

Taking this example code:

//Redis Variables
var redis = require('socket.io/node_modules/redis');
var RedisStore = require('socket.io/lib/stores/redis');
var pub = redis.createClient();
var sub = redis.createClient();
var client = redis.createClient();
var redis_store = new RedisStore({
                        redisPub: pub,
                        redisSub: sub,
                        redisClient: client
                      });

io.configure(function(){
  io.set('store', redis_store);  
});

Two Questions:

(1) pub, sub, and client are all connecting to the same redis database, correct?

(2) So what's the difference between them and what exactly are redisPub, redisSub, and redisClient used for?

Upvotes: 2

Views: 143

Answers (1)

Didier Spezia
Didier Spezia

Reputation: 73246

Yes, they are all connected to the same Redis instance, but they correspond to different connections to this instance.

When you use Redis pub/sub, it is mandatory to open several connections, because once a subscription is established on a given connection, it is not possible to use this connection for anything else:

  • sub is used to subscribe/unsuscribe and receive notification messages
  • pub is used to publish notifications
  • client is used for get/set/del/has/destroy methods

I guess pub and client could actually use the same Redis connection though.

Upvotes: 1

Related Questions