Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
01ca54e
commit 6848f3d
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |