Skip to content

Commit 321f8de

Browse files
authored
fix: unsubscribe not work with stringNumbers (#1710)
Closes #1643
1 parent 3ad7b0b commit 321f8de

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Diff for: lib/DataHandler.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export default class DataHandler {
176176
this.redis.condition.subscriber.del(replyType, channel);
177177
}
178178
const count = reply[2];
179-
if (count === 0) {
179+
if (Number(count) === 0) {
180180
this.redis.condition.subscriber = false;
181181
}
182182
const item = this.shiftCommand(reply);
@@ -209,7 +209,7 @@ export default class DataHandler {
209209
// Valid commands in the monitoring mode are AUTH and MONITOR,
210210
// both of which always reply with 'OK'.
211211
// So if we got an 'OK', we can make certain that
212-
// the reply is made to AUTH & MONITO.
212+
// the reply is made to AUTH & MONITOR.
213213
return false;
214214
}
215215

@@ -218,12 +218,12 @@ export default class DataHandler {
218218
// realtime monitor data instead of result of commands.
219219
const len = replyStr.indexOf(" ");
220220
const timestamp = replyStr.slice(0, len);
221-
const argindex = replyStr.indexOf('"');
221+
const argIndex = replyStr.indexOf('"');
222222
const args = replyStr
223-
.slice(argindex + 1, -1)
223+
.slice(argIndex + 1, -1)
224224
.split('" "')
225225
.map((elem) => elem.replace(/\\"/g, '"'));
226-
const dbAndSource = replyStr.slice(len + 2, argindex - 2).split(" ");
226+
const dbAndSource = replyStr.slice(len + 2, argIndex - 2).split(" ");
227227
this.redis.emit("monitor", timestamp, args, dbAndSource[1], dbAndSource[0]);
228228
return true;
229229
}
@@ -270,7 +270,7 @@ function fillUnsubCommand(command: Respondable, count: number) {
270270
: command.args.length;
271271

272272
if (remainingReplies === 0) {
273-
if (count === 0) {
273+
if (Number(count) === 0) {
274274
remainingRepliesMap.delete(command);
275275
command.resolve(count);
276276
return true;

Diff for: test/functional/pub_sub.ts

+9
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,13 @@ describe("pub/sub", function () {
204204
redis.disconnect(true);
205205
});
206206
});
207+
208+
it("should unsubscribe when stringNumbers is enabled", async () => {
209+
const redis = new Redis({ stringNumbers: true });
210+
await redis.subscribe("foo");
211+
const count = await redis.unsubscribe();
212+
expect(count).to.eql("0");
213+
expect(await redis.set("foo", "bar")).to.eql("OK");
214+
redis.disconnect();
215+
});
207216
});

0 commit comments

Comments
 (0)