diff --git a/lib/DataHandler.ts b/lib/DataHandler.ts index edf1f0ad..717de6de 100644 --- a/lib/DataHandler.ts +++ b/lib/DataHandler.ts @@ -176,7 +176,7 @@ export default class DataHandler { this.redis.condition.subscriber.del(replyType, channel); } const count = reply[2]; - if (count === 0) { + if (Number(count) === 0) { this.redis.condition.subscriber = false; } const item = this.shiftCommand(reply); @@ -209,7 +209,7 @@ export default class DataHandler { // Valid commands in the monitoring mode are AUTH and MONITOR, // both of which always reply with 'OK'. // So if we got an 'OK', we can make certain that - // the reply is made to AUTH & MONITO. + // the reply is made to AUTH & MONITOR. return false; } @@ -218,12 +218,12 @@ export default class DataHandler { // realtime monitor data instead of result of commands. const len = replyStr.indexOf(" "); const timestamp = replyStr.slice(0, len); - const argindex = replyStr.indexOf('"'); + const argIndex = replyStr.indexOf('"'); const args = replyStr - .slice(argindex + 1, -1) + .slice(argIndex + 1, -1) .split('" "') .map((elem) => elem.replace(/\\"/g, '"')); - const dbAndSource = replyStr.slice(len + 2, argindex - 2).split(" "); + const dbAndSource = replyStr.slice(len + 2, argIndex - 2).split(" "); this.redis.emit("monitor", timestamp, args, dbAndSource[1], dbAndSource[0]); return true; } @@ -270,7 +270,7 @@ function fillUnsubCommand(command: Respondable, count: number) { : command.args.length; if (remainingReplies === 0) { - if (count === 0) { + if (Number(count) === 0) { remainingRepliesMap.delete(command); command.resolve(count); return true; diff --git a/test/functional/pub_sub.ts b/test/functional/pub_sub.ts index 0d4b6519..b1147994 100644 --- a/test/functional/pub_sub.ts +++ b/test/functional/pub_sub.ts @@ -204,4 +204,13 @@ describe("pub/sub", function () { redis.disconnect(true); }); }); + + it("should unsubscribe when stringNumbers is enabled", async () => { + const redis = new Redis({ stringNumbers: true }); + await redis.subscribe("foo"); + const count = await redis.unsubscribe(); + expect(count).to.eql("0"); + expect(await redis.set("foo", "bar")).to.eql("OK"); + redis.disconnect(); + }); });