Skip to content

Commit 1cda848

Browse files
authored
fix(cmd): PUBSUB_NUMSUB return count as number (#3103)
fixes: #3102
1 parent d7c6544 commit 1cda848

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

packages/client/lib/commands/PUBSUB_NUMSUB.spec.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,38 @@ describe('PUBSUB NUMSUB', () => {
2727
});
2828
});
2929

30-
testUtils.testWithClient('client.pubSubNumSub', async client => {
30+
testUtils.testWithClient('client.pubSubNumSub resp2', async client => {
3131
assert.deepEqual(
3232
await client.pubSubNumSub(),
3333
Object.create(null)
3434
);
35-
}, GLOBAL.SERVERS.OPEN);
35+
36+
const res = await client.PUBSUB_NUMSUB(["test", "test2"]);
37+
assert.equal(res.test, 0);
38+
assert.equal(res.test2, 0);
39+
40+
}, {
41+
...GLOBAL.SERVERS.OPEN,
42+
clientOptions: {
43+
RESP: 2
44+
}
45+
});
46+
47+
testUtils.testWithClient('client.pubSubNumSub resp3', async client => {
48+
assert.deepEqual(
49+
await client.pubSubNumSub(),
50+
Object.create(null)
51+
);
52+
53+
const res = await client.PUBSUB_NUMSUB(["test", "test2"]);
54+
assert.equal(res.test, 0);
55+
assert.equal(res.test2, 0);
56+
57+
}, {
58+
...GLOBAL.SERVERS.OPEN,
59+
clientOptions: {
60+
RESP: 3
61+
}
62+
});
63+
3664
});

packages/client/lib/commands/PUBSUB_NUMSUB.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
IS_READ_ONLY: true,
88
/**
99
* Constructs the PUBSUB NUMSUB command
10-
*
10+
*
1111
* @param parser - The command parser
1212
* @param channels - Optional channel names to get subscription count for
1313
* @see https://redis.io/commands/pubsub-numsub/
@@ -21,15 +21,15 @@ export default {
2121
},
2222
/**
2323
* Transforms the PUBSUB NUMSUB reply into a record of channel name to subscriber count
24-
*
24+
*
2525
* @param rawReply - The raw reply from Redis
2626
* @returns Record mapping channel names to their subscriber counts
2727
*/
2828
transformReply(rawReply: UnwrapReply<ArrayReply<BlobStringReply | NumberReply>>) {
2929
const reply = Object.create(null);
3030
let i = 0;
3131
while (i < rawReply.length) {
32-
reply[rawReply[i++].toString()] = rawReply[i++].toString();
32+
reply[rawReply[i++].toString()] = Number(rawReply[i++]);
3333
}
3434

3535
return reply as Record<string, NumberReply>;

0 commit comments

Comments
 (0)