diff --git a/lib/client/pubsub.js b/lib/client/pubsub.js index acb03f3..97cf874 100644 --- a/lib/client/pubsub.js +++ b/lib/client/pubsub.js @@ -31,6 +31,13 @@ exports.subscribe = function () { }); } } + if ('function' === typeof arguments[arguments.length - 1]) { + var callback = arguments[arguments.length - 1]; + var channels = Array.prototype.slice.call(arguments, 0, arguments.length - 1); + process.nextTick(function () { + callback(null, ...channels); + }); + } }; /** @@ -53,6 +60,13 @@ exports.psubscribe = function () { }); } } + if ('function' === typeof arguments[arguments.length - 1]) { + var callback = arguments[arguments.length - 1]; + var channels = Array.prototype.slice.call(arguments, 0, arguments.length - 1); + process.nextTick(function () { + callback(null, ...channels); + }); + } }; /** * Unsubscribe @@ -83,7 +97,13 @@ exports.unsubscribe = function () { })(channelName)); } } - + if ('function' === typeof arguments[arguments.length - 1]) { + var callback = arguments[arguments.length - 1]; + var channels = Array.prototype.slice.call(arguments, 0, arguments.length - 1); + process.nextTick(function () { + callback(null, ...channels); + }); + } // TODO: If this was the last subscription, pub_sub_mode should be set to false this.pub_sub_mode = false; }; @@ -111,6 +131,13 @@ exports.punsubscribe = function () { }); } } + if ('function' === typeof arguments[arguments.length - 1]) { + var callback = arguments[arguments.length - 1]; + var channels = Array.prototype.slice.call(arguments, 0, arguments.length - 1); + process.nextTick(function () { + callback(null, ...channels); + }); + } // TODO: If this was the last subscription, pub_sub_mode should be set to false }; diff --git a/lib/server/keys.js b/lib/server/keys.js index 470ade3..391391e 100644 --- a/lib/server/keys.js +++ b/lib/server/keys.js @@ -15,7 +15,9 @@ exports.del = function (keys, callback) { for (let i = 0; i < keys.length; i++) { if (keys[i] in this.storage) { - + if (this.storage[keys[i]]._expire) { + clearTimeout(this.storage[keys[i]]._expire); + } delete this.storage[keys[i]]; keysDeleted++; @@ -25,6 +27,7 @@ exports.del = function (keys, callback) { helpers.callCallback(callback, null, keysDeleted); }; + /** * Exists */ diff --git a/test/client/redis-mock.pubsub.test.js b/test/client/redis-mock.pubsub.test.js index 109d9da..72d0eab 100644 --- a/test/client/redis-mock.pubsub.test.js +++ b/test/client/redis-mock.pubsub.test.js @@ -27,7 +27,10 @@ describe("publish and subscribe", function () { }); - r.subscribe(channelName); + r.subscribe(channelName, function (err, ch) { + should.equal(err, null); + should.equal(ch, channelName); + }); }); it("should unsubscribe to all channels if no arguments are given", function (done) { @@ -56,8 +59,14 @@ describe("publish and subscribe", function () { } }); - r.subscribe(channelNames[0]); - r.subscribe(channelNames[1]); + r.subscribe(channelNames[0], function (err, ch) { + should.equal(err, null); + should.equal(channelNames[0], channelNames[0]); + }); + r.subscribe(channelNames[1], function (err, ch) { + should.equal(err, null); + should.equal(ch, channelNames[1]); + }); }); it("should psubscribe and punsubscribe to a channel", function (done) { @@ -76,7 +85,10 @@ describe("publish and subscribe", function () { should.equal(ch, channelName); r.quit(done); }); - r.psubscribe(channelName); + r.psubscribe(channelName, function (err, ch) { + should.equal(err, null); + should.equal(ch, channelName); + }); }); it("suscribing and publishing with the same connection should make an error", function (done) {