Skip to content

Commit 6b2de37

Browse files
authored
Merge branch 'master' into parser
2 parents 8ec4855 + b1a0b48 commit 6b2de37

File tree

21 files changed

+379
-10
lines changed

21 files changed

+379
-10
lines changed

examples/topk.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ async function topK() {
6666
// ]
6767
console.log(top10);
6868

69+
// List out the top 10 with their counts (requires RedisBloom >=2.2.9)
70+
const top10WithCounts = await client.topK.listWithCount('mytopk');
71+
console.log('The top 10 with counts:');
72+
console.log(top10WithCounts);
73+
// top10WithCounts looks like this:
74+
// [
75+
// { item: 'suze', count: 42363 },
76+
// { item: 'lance', count: 41982 },
77+
// { item: 'simon', count: 41831 },
78+
// { item: 'steve', count: 39237 },
79+
// { item: 'guy', count: 39078 },
80+
// { item: 'kyleb', count: 37338 },
81+
// { item: 'leibale', count: 34230 },
82+
// { item: 'kyleo', count: 33812 },
83+
// { item: 'alex', count: 33679 },
84+
// { item: 'nava', count: 32663 }
85+
// ]
86+
6987
// Check if a few team members are in the top 10 with TOPK.QUERY:
7088
const [ steve, suze, leibale, frederick ] = await client.topK.query('mytopk', [
7189
'steve',

packages/bloom/lib/commands/top-k/LIST.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export const FIRST_KEY_INDEX = 1;
22

3+
export const IS_READ_ONLY = true;
4+
35
export function transformArguments(key: string): Array<string> {
46
return ['TOPK.LIST', key];
57
}
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 './LIST_WITHCOUNT';
4+
5+
describe('TOPK LIST WITHCOUNT', () => {
6+
testUtils.isVersionGreaterThanHook([2, 2, 9]);
7+
8+
it('transformArguments', () => {
9+
assert.deepEqual(
10+
transformArguments('key'),
11+
['TOPK.LIST', 'key', 'WITHCOUNT']
12+
);
13+
});
14+
15+
testUtils.testWithClient('client.topK.listWithCount', async client => {
16+
const [,, list] = await Promise.all([
17+
client.topK.reserve('key', 3),
18+
client.topK.add('key', 'item'),
19+
client.topK.listWithCount('key')
20+
]);
21+
22+
assert.deepEqual(
23+
list,
24+
[{
25+
item: 'item',
26+
count: 1
27+
}]
28+
);
29+
}, GLOBAL.SERVERS.OPEN);
30+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const FIRST_KEY_INDEX = 1;
2+
3+
export const IS_READ_ONLY = true;
4+
5+
export function transformArguments(key: string): Array<string> {
6+
return ['TOPK.LIST', key, 'WITHCOUNT'];
7+
}
8+
9+
type ListWithCountRawReply = Array<string | number>;
10+
11+
type ListWithCountReply = Array<{
12+
item: string,
13+
count: number
14+
}>;
15+
16+
export function transformReply(rawReply: ListWithCountRawReply): ListWithCountReply {
17+
const reply: ListWithCountReply = [];
18+
for (let i = 0; i < rawReply.length; i++) {
19+
reply.push({
20+
item: rawReply[i] as string,
21+
count: rawReply[++i] as number
22+
});
23+
}
24+
25+
return reply;
26+
}

packages/bloom/lib/commands/top-k/RESERVE.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export const FIRST_KEY_INDEX = 1;
22

3+
export const IS_READ_ONLY = true;
4+
35
interface ReserveOptions {
46
width: number;
57
depth: number;

packages/bloom/lib/commands/top-k/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as ADD from './ADD';
22
import * as COUNT from './COUNT';
33
import * as INCRBY from './INCRBY';
44
import * as INFO from './INFO';
5+
import * as LIST_WITHCOUNT from './LIST_WITHCOUNT';
56
import * as LIST from './LIST';
67
import * as QUERY from './QUERY';
78
import * as RESERVE from './RESERVE';
@@ -15,6 +16,8 @@ export default {
1516
incrBy: INCRBY,
1617
INFO,
1718
info: INFO,
19+
LIST_WITHCOUNT,
20+
listWithCount: LIST_WITHCOUNT,
1821
LIST,
1922
list: LIST,
2023
QUERY,

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';

0 commit comments

Comments
 (0)