Skip to content

Instantly share code, notes, and snippets.

@ngsankha
Created May 25, 2013 19:04
Show Gist options
  • Save ngsankha/5650349 to your computer and use it in GitHub Desktop.
Save ngsankha/5650349 to your computer and use it in GitHub Desktop.
A minimal chat client based on Redis pub/sub
var redis = require('redis'),
util = require('util'),
client1 = redis.createClient(),
client2 = redis.createClient();
channel = 'chatroom';
process.stdin.resume();
client1.on('error', function(err) {
console.log("Error: " + err);
});
client2.on('error', function(err) {
console.log("Error: " + err);
});
client1.on('message', function(channel, message) {
console.log(message);
});
client1.on('subscribe', function(channel, count) {
process.stdin.on('data', function(text) {
client2.publish(channel, text);
});
});
client1.subscribe(channel);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment