Skip to content

Commit

Permalink
use 2 redis clients for pub & sub
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Beckwith committed Feb 14, 2015
1 parent d2a33b2 commit 199d8ea
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,21 @@ var logger = new (winston.Logger)({
});
logger.info('Started wazstagram frontend process');

function createRedisClient() {
var redisPubClient = redis.createClient(
6379,
nconf.get('redisHost'),
{
auth_pass: nconf.get('redisKey'),
return_buffers: true
}
).on("error", function (err) {
logger.error("Error connecting to redis: " + err);
});
}

// set up redis connection
var redisClient = redis.createClient(
var redisSubClient = redis.createClient(
6379,
nconf.get('redisHost'),
{
Expand All @@ -40,6 +53,8 @@ var redisClient = redis.createClient(
).on("error", function (err) {
logger.error("Error connecting to redis: " + err);
});
var redisSubClient = createRedisClient();
var redisPubClient = createRedisClient();

// configure service bus
var picCache = new Object();
Expand Down Expand Up @@ -115,7 +130,7 @@ io.sockets.on('connection', function (socket) {
});

// listen to new images from redis pub/sub
redisClient.on('message', function(channel, message) {
redisSubClient.on('message', function(channel, message) {
logger.info('channel: ' + channel + " ; message: " + message);
io.sockets.in (message.city).emit('newPic', message.pic);
io.sockets.in (universe).emit('newPic', message.pic);
Expand All @@ -126,7 +141,7 @@ redisClient.on('message', function(channel, message) {
function publishImage(message) {
logger.info('new pic published from: ' + message.city);
//cachePic(message.pic, message.city);
redisClient.publish('pics', message);
redisPubClient.publish('pics', message);
}


Expand Down

0 comments on commit 199d8ea

Please sign in to comment.