Created
October 8, 2015 14:58
-
-
Save elyas-bhy/b6d2aaa2db1880fd3042 to your computer and use it in GitHub Desktop.
Redis potential bug replication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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