Skip to content
Open
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
32 changes: 30 additions & 2 deletions packages/client/lib/commands/PUBSUB_NUMSUB.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,38 @@ describe('PUBSUB NUMSUB', () => {
});
});

testUtils.testWithClient('client.pubSubNumSub', async client => {
testUtils.testWithClient('client.pubSubNumSub resp2', async client => {
assert.deepEqual(
await client.pubSubNumSub(),
Object.create(null)
);
}, GLOBAL.SERVERS.OPEN);

const res = await client.PUBSUB_NUMSUB(["test", "test2"]);
assert.equal(res.test, 0);
assert.equal(res.test2, 0);

}, {
...GLOBAL.SERVERS.OPEN,
clientOptions: {
RESP: 2
}
});

testUtils.testWithClient('client.pubSubNumSub resp3', async client => {
assert.deepEqual(
await client.pubSubNumSub(),
Object.create(null)
);

const res = await client.PUBSUB_NUMSUB(["test", "test2"]);
assert.equal(res.test, 0);
assert.equal(res.test2, 0);

}, {
...GLOBAL.SERVERS.OPEN,
clientOptions: {
RESP: 3
}
});

});
6 changes: 3 additions & 3 deletions packages/client/lib/commands/PUBSUB_NUMSUB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
IS_READ_ONLY: true,
/**
* Constructs the PUBSUB NUMSUB command
*
*
* @param parser - The command parser
* @param channels - Optional channel names to get subscription count for
* @see https://redis.io/commands/pubsub-numsub/
Expand All @@ -21,15 +21,15 @@ export default {
},
/**
* Transforms the PUBSUB NUMSUB reply into a record of channel name to subscriber count
*
*
* @param rawReply - The raw reply from Redis
* @returns Record mapping channel names to their subscriber counts
*/
transformReply(rawReply: UnwrapReply<ArrayReply<BlobStringReply | NumberReply>>) {
const reply = Object.create(null);
let i = 0;
while (i < rawReply.length) {
reply[rawReply[i++].toString()] = rawReply[i++].toString();
reply[rawReply[i++].toString()] = Number(rawReply[i++]);
}

return reply as Record<string, NumberReply>;
Expand Down
Loading