Skip to content

Commit 8a84878

Browse files
authored
Merge 1618630 into d8ae8cf
2 parents d8ae8cf + 1618630 commit 8a84878

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

packages/client/lib/client/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import * as PUBSUB_CHANNELS from '../commands/PUBSUB_CHANNELS';
101101
import * as PUBSUB_NUMPAT from '../commands/PUBSUB_NUMPAT';
102102
import * as PUBSUB_NUMSUB from '../commands/PUBSUB_NUMSUB';
103103
import * as PUBSUB_SHARDCHANNELS from '../commands/PUBSUB_SHARDCHANNELS';
104+
import * as PUBSUB_SHARDNUMSUB from '../commands/PUBSUB_SHARDNUMSUB';
104105
import * as RANDOMKEY from '../commands/RANDOMKEY';
105106
import * as READONLY from '../commands/READONLY';
106107
import * as READWRITE from '../commands/READWRITE';
@@ -326,6 +327,8 @@ export default {
326327
pubSubNumSub: PUBSUB_NUMSUB,
327328
PUBSUB_SHARDCHANNELS,
328329
pubSubShardChannels: PUBSUB_SHARDCHANNELS,
330+
PUBSUB_SHARDNUMSUB,
331+
pubSubShardNumSub: PUBSUB_SHARDNUMSUB,
329332
RANDOMKEY,
330333
randomKey: RANDOMKEY,
331334
READONLY,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './PUBSUB_SHARDNUMSUB';
4+
5+
describe('PUBSUB SHARDNUMSUB', () => {
6+
testUtils.isVersionGreaterThanHook([7]);
7+
8+
describe('transformArguments', () => {
9+
it('simple', () => {
10+
assert.deepEqual(
11+
transformArguments(),
12+
['PUBSUB', 'SHARDNUMSUB']
13+
);
14+
});
15+
16+
it('string', () => {
17+
assert.deepEqual(
18+
transformArguments('channel'),
19+
['PUBSUB', 'SHARDNUMSUB', 'channel']
20+
);
21+
});
22+
23+
it('array', () => {
24+
assert.deepEqual(
25+
transformArguments(['1', '2']),
26+
['PUBSUB', 'SHARDNUMSUB', '1', '2']
27+
);
28+
});
29+
});
30+
31+
testUtils.testWithClient('client.pubSubShardNumSub', async client => {
32+
assert.deepEqual(
33+
await client.pubSubShardNumSub(['foo', 'bar']),
34+
Object.create(null, {
35+
foo: {
36+
value: 0,
37+
configurable: true,
38+
enumerable: true
39+
},
40+
bar: {
41+
value: 0,
42+
configurable: true,
43+
enumerable: true
44+
}
45+
})
46+
);
47+
}, GLOBAL.SERVERS.OPEN);
48+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { pushVerdictArguments } from './generic-transformers';
2+
import { RedisCommandArgument, RedisCommandArguments } from '.';
3+
4+
export const IS_READ_ONLY = true;
5+
6+
export function transformArguments(
7+
channels?: Array<RedisCommandArgument> | RedisCommandArgument
8+
): RedisCommandArguments {
9+
const args = ['PUBSUB', 'SHARDNUMSUB'];
10+
11+
if (channels) return pushVerdictArguments(args, channels);
12+
13+
return args;
14+
}
15+
16+
export function transformReply(rawReply: Array<string | number>): Record<string, number> {
17+
const transformedReply = Object.create(null);
18+
19+
for (let i = 0; i < rawReply.length; i += 2) {
20+
transformedReply[rawReply[i]] = rawReply[i + 1];
21+
}
22+
23+
return transformedReply;
24+
}

0 commit comments

Comments
 (0)