Skip to content

Instantly share code, notes, and snippets.

@luin
Forked from elyas-bhy/redis-test.js
Last active December 1, 2021 02:01
Show Gist options
  • Save luin/978d6e95aa2160718f9b to your computer and use it in GitHub Desktop.
Save luin/978d6e95aa2160718f9b 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.removeAllListeners('subscribe');
subscriber.removeAllListeners('message');
subscriber.removeAllListeners('unsubscribe');
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