Skip to content

Instantly share code, notes, and snippets.

@elyas-bhy
Created October 8, 2015 14:58
Show Gist options
  • Save elyas-bhy/b6d2aaa2db1880fd3042 to your computer and use it in GitHub Desktop.
Save elyas-bhy/b6d2aaa2db1880fd3042 to your computer and use it in GitHub Desktop.
Redis potential bug replication
var redis = require('redis');
var options = {
host: '127.0.0.1',
port: '6379'
};
var publisher = redis.createClient(options);
var subscriber = redis.createClient(options);
function sub(message) {
subscriber.on('subscribe', function () {
console.log('publishing');
publisher.publish('/foo', message);
});
subscriber.on('message', function (channel, message) {
console.log('message: ' + message);
});
subscriber.on('unsubscribe', function (channel, count) {
console.log('unsub: ' + count);
});
subscriber.subscribe('/foo');
}
sub('hello');
setTimeout(function () {
subscriber.unsubscribe();
setTimeout(function () {
sub('world');
}, 4000);
}, 4000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment