Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unsubscribe not work with stringNumbers #1710

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (Number(count) === 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
9 changes: 9 additions & 0 deletions test/functional/pub_sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});