You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Add support for PUBSUB SHARDNUMSUB
(#2541)
* Add support for command 'PUBSUB SHARDNUMSUB' * Use import from PUBSUB_SHARDNUMSUB * Add test case for non-empty reply * clean tests * run tests in redis >= 7, fix integration test --------- Co-authored-by: Leibale Eidelman <me@leibale.com>
This commit is contained in:
@@ -102,6 +102,7 @@ import * as PUBSUB_CHANNELS from '../commands/PUBSUB_CHANNELS';
|
|||||||
import * as PUBSUB_NUMPAT from '../commands/PUBSUB_NUMPAT';
|
import * as PUBSUB_NUMPAT from '../commands/PUBSUB_NUMPAT';
|
||||||
import * as PUBSUB_NUMSUB from '../commands/PUBSUB_NUMSUB';
|
import * as PUBSUB_NUMSUB from '../commands/PUBSUB_NUMSUB';
|
||||||
import * as PUBSUB_SHARDCHANNELS from '../commands/PUBSUB_SHARDCHANNELS';
|
import * as PUBSUB_SHARDCHANNELS from '../commands/PUBSUB_SHARDCHANNELS';
|
||||||
|
import * as PUBSUB_SHARDNUMSUB from '../commands/PUBSUB_SHARDNUMSUB';
|
||||||
import * as RANDOMKEY from '../commands/RANDOMKEY';
|
import * as RANDOMKEY from '../commands/RANDOMKEY';
|
||||||
import * as READONLY from '../commands/READONLY';
|
import * as READONLY from '../commands/READONLY';
|
||||||
import * as READWRITE from '../commands/READWRITE';
|
import * as READWRITE from '../commands/READWRITE';
|
||||||
@@ -329,6 +330,8 @@ export default {
|
|||||||
pubSubNumSub: PUBSUB_NUMSUB,
|
pubSubNumSub: PUBSUB_NUMSUB,
|
||||||
PUBSUB_SHARDCHANNELS,
|
PUBSUB_SHARDCHANNELS,
|
||||||
pubSubShardChannels: PUBSUB_SHARDCHANNELS,
|
pubSubShardChannels: PUBSUB_SHARDCHANNELS,
|
||||||
|
PUBSUB_SHARDNUMSUB,
|
||||||
|
pubSubShardNumSub: PUBSUB_SHARDNUMSUB,
|
||||||
RANDOMKEY,
|
RANDOMKEY,
|
||||||
randomKey: RANDOMKEY,
|
randomKey: RANDOMKEY,
|
||||||
READONLY,
|
READONLY,
|
||||||
|
48
packages/client/lib/commands/PUBSUB_SHARDNUMSUB.spec.ts
Normal file
48
packages/client/lib/commands/PUBSUB_SHARDNUMSUB.spec.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { strict as assert } from 'assert';
|
||||||
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
|
import { transformArguments } from './PUBSUB_SHARDNUMSUB';
|
||||||
|
|
||||||
|
describe('PUBSUB SHARDNUMSUB', () => {
|
||||||
|
testUtils.isVersionGreaterThanHook([7]);
|
||||||
|
|
||||||
|
describe('transformArguments', () => {
|
||||||
|
it('simple', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments(),
|
||||||
|
['PUBSUB', 'SHARDNUMSUB']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('string', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('channel'),
|
||||||
|
['PUBSUB', 'SHARDNUMSUB', 'channel']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('array', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments(['1', '2']),
|
||||||
|
['PUBSUB', 'SHARDNUMSUB', '1', '2']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
testUtils.testWithClient('client.pubSubShardNumSub', async client => {
|
||||||
|
assert.deepEqual(
|
||||||
|
await client.pubSubShardNumSub(['foo', 'bar']),
|
||||||
|
Object.create(null, {
|
||||||
|
foo: {
|
||||||
|
value: 0,
|
||||||
|
configurable: true,
|
||||||
|
enumerable: true
|
||||||
|
},
|
||||||
|
bar: {
|
||||||
|
value: 0,
|
||||||
|
configurable: true,
|
||||||
|
enumerable: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
});
|
24
packages/client/lib/commands/PUBSUB_SHARDNUMSUB.ts
Normal file
24
packages/client/lib/commands/PUBSUB_SHARDNUMSUB.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { pushVerdictArguments } from './generic-transformers';
|
||||||
|
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||||
|
|
||||||
|
export const IS_READ_ONLY = true;
|
||||||
|
|
||||||
|
export function transformArguments(
|
||||||
|
channels?: Array<RedisCommandArgument> | RedisCommandArgument
|
||||||
|
): RedisCommandArguments {
|
||||||
|
const args = ['PUBSUB', 'SHARDNUMSUB'];
|
||||||
|
|
||||||
|
if (channels) return pushVerdictArguments(args, channels);
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function transformReply(rawReply: Array<string | number>): Record<string, number> {
|
||||||
|
const transformedReply = Object.create(null);
|
||||||
|
|
||||||
|
for (let i = 0; i < rawReply.length; i += 2) {
|
||||||
|
transformedReply[rawReply[i]] = rawReply[i + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return transformedReply;
|
||||||
|
}
|
Reference in New Issue
Block a user