Skip to content

Commit 875298e

Browse files
Avital-Fineleibale
andauthored
Support ZINTERCARD and SINTERCARD (#2040)
* Support ZINTERCARD and SINTERCARD * clean code * clean code Co-authored-by: leibale <[email protected]>
1 parent be51abe commit 875298e

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

packages/client/lib/cluster/commands.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import * as SETEX from '../commands/SETEX';
9898
import * as SETNX from '../commands/SETNX';
9999
import * as SETRANGE from '../commands/SETRANGE';
100100
import * as SINTER from '../commands/SINTER';
101+
import * as SINTERCARD from '../commands/SINTERCARD';
101102
import * as SINTERSTORE from '../commands/SINTERSTORE';
102103
import * as SISMEMBER from '../commands/SISMEMBER';
103104
import * as SMEMBERS from '../commands/SMEMBERS';
@@ -149,6 +150,7 @@ import * as ZDIFFSTORE from '../commands/ZDIFFSTORE';
149150
import * as ZINCRBY from '../commands/ZINCRBY';
150151
import * as ZINTER_WITHSCORES from '../commands/ZINTER_WITHSCORES';
151152
import * as ZINTER from '../commands/ZINTER';
153+
import * as ZINTERCARD from '../commands/ZINTERCARD';
152154
import * as ZINTERSTORE from '../commands/ZINTERSTORE';
153155
import * as ZLEXCOUNT from '../commands/ZLEXCOUNT';
154156
import * as ZMSCORE from '../commands/ZMSCORE';
@@ -366,6 +368,8 @@ export default {
366368
sDiffStore: SDIFFSTORE,
367369
SINTER,
368370
sInter: SINTER,
371+
SINTERCARD,
372+
sInterCard: SINTERCARD,
369373
SINTERSTORE,
370374
sInterStore: SINTERSTORE,
371375
SET,
@@ -478,6 +482,8 @@ export default {
478482
zInterWithScores: ZINTER_WITHSCORES,
479483
ZINTER,
480484
zInter: ZINTER,
485+
ZINTERCARD,
486+
zInterCard: ZINTERCARD,
481487
ZINTERSTORE,
482488
zInterStore: ZINTERSTORE,
483489
ZLEXCOUNT,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './SINTERCARD';
4+
5+
describe('SINTERCARD', () => {
6+
testUtils.isVersionGreaterThanHook([7, 0]);
7+
8+
describe('transformArguments', () => {
9+
it('simple', () => {
10+
assert.deepEqual(
11+
transformArguments(['1', '2']),
12+
['SINTERCARD', '2', '1', '2']
13+
);
14+
});
15+
16+
it('with limit', () => {
17+
assert.deepEqual(
18+
transformArguments(['1', '2'], 1),
19+
['SINTERCARD', '2', '1', '2', 'LIMIT', '1']
20+
);
21+
});
22+
});
23+
24+
testUtils.testWithClient('client.sInterCard', async client => {
25+
assert.deepEqual(
26+
await client.sInterCard('key'),
27+
0
28+
);
29+
}, GLOBAL.SERVERS.OPEN);
30+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { RedisCommandArgument, RedisCommandArguments } from '.';
2+
import { pushVerdictArgument } from './generic-transformers';
3+
4+
export const FIRST_KEY_INDEX = 2;
5+
6+
export const IS_READ_ONLY = true;
7+
8+
export function transformArguments(
9+
keys: Array<RedisCommandArgument> | RedisCommandArgument,
10+
limit?: number
11+
): RedisCommandArguments {
12+
const args = pushVerdictArgument(['SINTERCARD'], keys);
13+
14+
if (limit) {
15+
args.push('LIMIT', limit.toString());
16+
}
17+
18+
return args;
19+
}
20+
21+
export declare function transformReply(): number;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './ZINTERCARD';
4+
5+
describe('ZINTERCARD', () => {
6+
testUtils.isVersionGreaterThanHook([7, 0]);
7+
8+
describe('transformArguments', () => {
9+
it('simple', () => {
10+
assert.deepEqual(
11+
transformArguments(['1', '2']),
12+
['ZINTERCARD', '2', '1', '2']
13+
);
14+
});
15+
16+
it('with limit', () => {
17+
assert.deepEqual(
18+
transformArguments(['1', '2'], 1),
19+
['ZINTERCARD', '2', '1', '2', 'LIMIT', '1']
20+
);
21+
});
22+
});
23+
24+
testUtils.testWithClient('client.zInterCard', async client => {
25+
assert.deepEqual(
26+
await client.zInterCard('key'),
27+
0
28+
);
29+
}, GLOBAL.SERVERS.OPEN);
30+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { RedisCommandArgument, RedisCommandArguments } from '.';
2+
import { pushVerdictArgument } from './generic-transformers';
3+
4+
export const FIRST_KEY_INDEX = 2;
5+
6+
export const IS_READ_ONLY = true;
7+
8+
export function transformArguments(
9+
keys: Array<RedisCommandArgument> | RedisCommandArgument,
10+
limit?: number
11+
): RedisCommandArguments {
12+
const args = pushVerdictArgument(['ZINTERCARD'], keys);
13+
14+
if (limit) {
15+
args.push('LIMIT', limit.toString());
16+
}
17+
18+
return args;
19+
}
20+
21+
export declare function transformReply(): number;

0 commit comments

Comments
 (0)