Skip to content

Commit

Permalink
Fix unsubscribe not work with stringNumbers
Browse files Browse the repository at this point in the history
Closes #1643
  • Loading branch information
luin committed Jan 25, 2023
1 parent 6285e80 commit 88e3e03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/DataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default class DataHandler {
this.redis.condition.subscriber.del(replyType, channel);
}
const count = reply[2];
if (count === 0) {
if (count === Number(0)) {
this.redis.condition.subscriber = false;
}
const item = this.shiftCommand(reply);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions test/functional/pub_sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,12 @@ 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");
redis.disconnect();
});
});

0 comments on commit 88e3e03

Please sign in to comment.