You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
@@ -1,5 +1,7 @@
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(key: string): Array<string> {
|
||||
return ['TOPK.LIST', key];
|
||||
}
|
||||
|
30
packages/bloom/lib/commands/top-k/LIST_WITHCOUNT.spec.ts
Normal file
30
packages/bloom/lib/commands/top-k/LIST_WITHCOUNT.spec.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../../test-utils';
|
||||
import { transformArguments } from './LIST_WITHCOUNT';
|
||||
|
||||
describe('TOPK LIST WITHCOUNT', () => {
|
||||
testUtils.isVersionGreaterThanHook([2, 2, 9]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key'),
|
||||
['TOPK.LIST', 'key', 'WITHCOUNT']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.topK.listWithCount', async client => {
|
||||
const [,, list] = await Promise.all([
|
||||
client.topK.reserve('key', 3),
|
||||
client.topK.add('key', 'item'),
|
||||
client.topK.listWithCount('key')
|
||||
]);
|
||||
|
||||
assert.deepEqual(
|
||||
list,
|
||||
[{
|
||||
item: 'item',
|
||||
count: 1
|
||||
}]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
26
packages/bloom/lib/commands/top-k/LIST_WITHCOUNT.ts
Normal file
26
packages/bloom/lib/commands/top-k/LIST_WITHCOUNT.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(key: string): Array<string> {
|
||||
return ['TOPK.LIST', key, 'WITHCOUNT'];
|
||||
}
|
||||
|
||||
type ListWithCountRawReply = Array<string | number>;
|
||||
|
||||
type ListWithCountReply = Array<{
|
||||
item: string,
|
||||
count: number
|
||||
}>;
|
||||
|
||||
export function transformReply(rawReply: ListWithCountRawReply): ListWithCountReply {
|
||||
const reply: ListWithCountReply = [];
|
||||
for (let i = 0; i < rawReply.length; i++) {
|
||||
reply.push({
|
||||
item: rawReply[i] as string,
|
||||
count: rawReply[++i] as number
|
||||
});
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
@@ -1,5 +1,7 @@
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
interface ReserveOptions {
|
||||
width: number;
|
||||
depth: number;
|
||||
|
@@ -2,6 +2,7 @@ import * as ADD from './ADD';
|
||||
import * as COUNT from './COUNT';
|
||||
import * as INCRBY from './INCRBY';
|
||||
import * as INFO from './INFO';
|
||||
import * as LIST_WITHCOUNT from './LIST_WITHCOUNT';
|
||||
import * as LIST from './LIST';
|
||||
import * as QUERY from './QUERY';
|
||||
import * as RESERVE from './RESERVE';
|
||||
@@ -15,6 +16,8 @@ export default {
|
||||
incrBy: INCRBY,
|
||||
INFO,
|
||||
info: INFO,
|
||||
LIST_WITHCOUNT,
|
||||
listWithCount: LIST_WITHCOUNT,
|
||||
LIST,
|
||||
list: LIST,
|
||||
QUERY,
|
||||
|
Reference in New Issue
Block a user