Skip to content

Commit b1a0b48

Browse files
Avital-Fineleibale
andauthored
Support new muilti pop commands (#2051)
* Support new muilti pop commands * remove .only * clean code * fix for 4558ec6 * fix tests Co-authored-by: leibale <[email protected]>
1 parent 0f7ae93 commit b1a0b48

File tree

15 files changed

+298
-10
lines changed

15 files changed

+298
-10
lines changed

packages/client/lib/cluster/commands.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import * as BITFIELD from '../commands/BITFIELD';
66
import * as BITOP from '../commands/BITOP';
77
import * as BITPOS from '../commands/BITPOS';
88
import * as BLMOVE from '../commands/BLMOVE';
9+
import * as BLMPOP from '../commands/BLMPOP';
910
import * as BLPOP from '../commands/BLPOP';
1011
import * as BRPOP from '../commands/BRPOP';
1112
import * as BRPOPLPUSH from '../commands/BRPOPLPUSH';
13+
import * as BZMPOP from '../commands/BZMPOP';
1214
import * as BZPOPMAX from '../commands/BZPOPMAX';
1315
import * as BZPOPMIN from '../commands/BZPOPMIN';
1416
import * as COPY from '../commands/COPY';
@@ -59,6 +61,7 @@ import * as LINDEX from '../commands/LINDEX';
5961
import * as LINSERT from '../commands/LINSERT';
6062
import * as LLEN from '../commands/LLEN';
6163
import * as LMOVE from '../commands/LMOVE';
64+
import * as LMPOP from '../commands/LMPOP';
6265
import * as LPOP_COUNT from '../commands/LPOP_COUNT';
6366
import * as LPOP from '../commands/LPOP';
6467
import * as LPOS_COUNT from '../commands/LPOS_COUNT';
@@ -161,6 +164,7 @@ import * as ZINTER from '../commands/ZINTER';
161164
import * as ZINTERCARD from '../commands/ZINTERCARD';
162165
import * as ZINTERSTORE from '../commands/ZINTERSTORE';
163166
import * as ZLEXCOUNT from '../commands/ZLEXCOUNT';
167+
import * as ZMPOP from '../commands/ZMPOP';
164168
import * as ZMSCORE from '../commands/ZMSCORE';
165169
import * as ZPOPMAX_COUNT from '../commands/ZPOPMAX_COUNT';
166170
import * as ZPOPMAX from '../commands/ZPOPMAX';
@@ -202,12 +206,16 @@ export default {
202206
bitPos: BITPOS,
203207
BLMOVE,
204208
blMove: BLMOVE,
209+
BLMPOP,
210+
blmPop: BLMPOP,
205211
BLPOP,
206212
blPop: BLPOP,
207213
BRPOP,
208214
brPop: BRPOP,
209215
BRPOPLPUSH,
210216
brPopLPush: BRPOPLPUSH,
217+
BZMPOP,
218+
bzmPop: BZMPOP,
211219
BZPOPMAX,
212220
bzPopMax: BZPOPMAX,
213221
BZPOPMIN,
@@ -308,6 +316,8 @@ export default {
308316
lLen: LLEN,
309317
LMOVE,
310318
lMove: LMOVE,
319+
LMPOP,
320+
lmPop: LMPOP,
311321
LPOP_COUNT,
312322
lPopCount: LPOP_COUNT,
313323
LPOP,
@@ -512,6 +522,8 @@ export default {
512522
zInterStore: ZINTERSTORE,
513523
ZLEXCOUNT,
514524
zLexCount: ZLEXCOUNT,
525+
ZMPOP,
526+
zmPop: ZMPOP,
515527
ZMSCORE,
516528
zmScore: ZMSCORE,
517529
ZPOPMAX_COUNT,

packages/client/lib/commands/BLMOVE.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { RedisCommandArgument, RedisCommandArguments } from '.';
2-
import { LMoveSide } from './LMOVE';
2+
import { ListSide } from './generic-transformers';
33

44
export const FIRST_KEY_INDEX = 1;
55

66
export function transformArguments(
77
source: RedisCommandArgument,
88
destination: RedisCommandArgument,
9-
sourceDirection: LMoveSide,
10-
destinationDirection: LMoveSide,
9+
sourceDirection: ListSide,
10+
destinationDirection: ListSide,
1111
timeout: number
1212
): RedisCommandArguments {
1313
return [
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './BLMPOP';
4+
5+
describe('BLMPOP', () => {
6+
testUtils.isVersionGreaterThanHook([7, 0]);
7+
8+
describe('transformArguments', () => {
9+
it('simple', () => {
10+
assert.deepEqual(
11+
transformArguments(0, 'key', 'LEFT'),
12+
['BLMPOP', '0', '1', 'key', 'LEFT']
13+
);
14+
});
15+
16+
it('with COUNT', () => {
17+
assert.deepEqual(
18+
transformArguments(0, 'key', 'LEFT', {
19+
COUNT: 2
20+
}),
21+
['BLMPOP', '0', '1', 'key', 'LEFT', 'COUNT', '2']
22+
);
23+
});
24+
});
25+
26+
testUtils.testWithClient('client.blmPop', async client => {
27+
assert.deepEqual(
28+
await client.blmPop(1, 'key', 'RIGHT'),
29+
null
30+
);
31+
}, GLOBAL.SERVERS.OPEN);
32+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { RedisCommandArgument, RedisCommandArguments } from '.';
2+
import { transformLMPopArguments, LMPopOptions, ListSide } from './generic-transformers';
3+
4+
export const FIRST_KEY_INDEX = 3;
5+
6+
export function transformArguments(
7+
timeout: number,
8+
keys: RedisCommandArgument | Array<RedisCommandArgument>,
9+
side: ListSide,
10+
options?: LMPopOptions
11+
): RedisCommandArguments {
12+
return transformLMPopArguments(
13+
['BLMPOP', timeout.toString()],
14+
keys,
15+
side,
16+
options
17+
);
18+
}
19+
20+
export { transformReply } from './LMPOP';

packages/client/lib/commands/BLPOP.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('BLPOP', () => {
6565
'key',
6666
1
6767
),
68-
cluster.lPush('key', 'element'),
68+
cluster.lPush('key', 'element')
6969
]);
7070

7171
assert.deepEqual(
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './BZMPOP';
4+
5+
describe('BZMPOP', () => {
6+
testUtils.isVersionGreaterThanHook([7, 0]);
7+
8+
describe('transformArguments', () => {
9+
it('simple', () => {
10+
assert.deepEqual(
11+
transformArguments(0, 'key', 'MIN'),
12+
['BZMPOP', '0', '1', 'key', 'MIN']
13+
);
14+
});
15+
16+
it('with COUNT', () => {
17+
assert.deepEqual(
18+
transformArguments(0, 'key', 'MIN', {
19+
COUNT: 2
20+
}),
21+
['BZMPOP', '0', '1', 'key', 'MIN', 'COUNT', '2']
22+
);
23+
});
24+
});
25+
26+
testUtils.testWithClient('client.bzmPop', async client => {
27+
assert.deepEqual(
28+
await client.bzmPop(1, 'key', 'MAX'),
29+
null
30+
);
31+
}, GLOBAL.SERVERS.OPEN);
32+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { RedisCommandArgument, RedisCommandArguments } from '.';
2+
import { SortedSetSide, transformZMPopArguments, ZMPopOptions } from './generic-transformers';
3+
4+
export const FIRST_KEY_INDEX = 3;
5+
6+
export function transformArguments(
7+
timeout: number,
8+
keys: RedisCommandArgument | Array<RedisCommandArgument>,
9+
side: SortedSetSide,
10+
options?: ZMPopOptions
11+
): RedisCommandArguments {
12+
return transformZMPopArguments(
13+
['BZMPOP', timeout.toString()],
14+
keys,
15+
side,
16+
options
17+
);
18+
}
19+
20+
export { transformReply } from './ZMPOP';

packages/client/lib/commands/BZPOPMAX.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('BZPOPMAX', () => {
4545
client.bzPopMax(
4646
commandOptions({ isolated: true }),
4747
'key',
48-
0
48+
1
4949
),
5050
client.zAdd('key', [{
5151
value: '1',

packages/client/lib/commands/BZPOPMIN.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('BZPOPMIN', () => {
4545
client.bzPopMin(
4646
commandOptions({ isolated: true }),
4747
'key',
48-
0
48+
1
4949
),
5050
client.zAdd('key', [{
5151
value: '1',

packages/client/lib/commands/LMOVE.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { RedisCommandArgument, RedisCommandArguments } from '.';
2+
import { ListSide } from './generic-transformers';
23

34
export const FIRST_KEY_INDEX = 1;
45

5-
export type LMoveSide = 'LEFT' | 'RIGHT';
6-
76
export function transformArguments(
87
source: RedisCommandArgument,
98
destination: RedisCommandArgument,
10-
sourceSide: LMoveSide,
11-
destinationSide: LMoveSide
9+
sourceSide: ListSide,
10+
destinationSide: ListSide
1211
): RedisCommandArguments {
1312
return [
1413
'LMOVE',

0 commit comments

Comments
 (0)