1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Bloom commands (#1786)

* ft.alter

* bloom commands

* tdigest

* delete tdigest

* uncomment tests

* small changes

* Update MADD.ts

* small changes

* clean code

* Update README.md

* Update README.md

Co-authored-by: leibale <leibale1998@gmail.com>
This commit is contained in:
Avital Fine
2021-12-29 17:55:09 +01:00
committed by GitHub
parent fd72a287b7
commit f93ac04436
84 changed files with 1760 additions and 5 deletions

View File

@@ -0,0 +1,22 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../../test-utils';
import { transformArguments } from './ADD';
describe('TOPK ADD', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', 'item'),
['TOPK.ADD', 'key', 'item']
);
});
testUtils.testWithClient('client.topK.add', async client => {
await client.topK.reserve('topK', 3);
assert.deepEqual(
await client.topK.add('topK', 'item'),
[null]
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,13 @@
import { RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
import { pushVerdictArguments } from '@node-redis/client/dist/lib/commands/generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(
key: string,
items: string | Array<string>
): RedisCommandArguments {
return pushVerdictArguments(['TOPK.ADD', key], items);
}
export declare function transformReply(): Array<null | string>;

View File

@@ -0,0 +1,21 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../../test-utils';
import { transformArguments } from './COUNT';
describe('TOPK COUNT', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', 'item'),
['TOPK.COUNT', 'key', 'item']
);
});
testUtils.testWithClient('client.topK.count', async client => {
await client.topK.reserve('key', 3);
assert.deepEqual(
await client.topK.count('key', 'item'),
[0]
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,15 @@
import { RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
import { pushVerdictArguments } from '@node-redis/client/dist/lib/commands/generic-transformers';
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
export function transformArguments(
key: string,
items: string | Array<string>
): RedisCommandArguments {
return pushVerdictArguments(['TOPK.COUNT', key], items);
}
export declare function transformReply(): Array<number>;

View File

@@ -0,0 +1,42 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../../test-utils';
import { transformArguments } from './INCRBY';
describe('TOPK INCRBY', () => {
describe('transformArguments', () => {
it('single item', () => {
assert.deepEqual(
transformArguments('key', {
item: 'item',
incrementBy: 1
}),
['TOPK.INCRBY', 'key', 'item', '1']
);
});
it('multiple items', () => {
assert.deepEqual(
transformArguments('key', [{
item: 'a',
incrementBy: 1
}, {
item: 'b',
incrementBy: 2
}]),
['TOPK.INCRBY', 'key', 'a', '1', 'b', '2']
);
});
});
testUtils.testWithClient('client.topK.incrby', async client => {
await client.topK.reserve('key', 5);
assert.deepEqual(
await client.topK.incrBy('key', {
item: 'item',
incrementBy: 1
}),
[null]
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,29 @@
export const FIRST_KEY_INDEX = 1;
interface IncrByItem {
item: string;
incrementBy: number;
}
export function transformArguments(
key: string,
items: IncrByItem | Array<IncrByItem>
): Array<string> {
const args = ['TOPK.INCRBY', key];
if (Array.isArray(items)) {
for (const item of items) {
pushIncrByItem(args, item);
}
} else {
pushIncrByItem(args, items);
}
return args;
}
function pushIncrByItem(args: Array<string>, { item, incrementBy }: IncrByItem): void {
args.push(item, incrementBy.toString());
}
export declare function transformReply(): Array<string | null>;

View File

@@ -0,0 +1,23 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../../test-utils';
import { transformArguments } from './INFO';
describe('TOPK INFO', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
['TOPK.INFO', 'key']
);
});
testUtils.testWithClient('client.topK.info', async client => {
await client.topK.reserve('key', 3);
const info = await client.topK.info('key');
assert.equal(typeof info, 'object');
assert.equal(info.k, 3);
assert.equal(typeof info.width, 'number');
assert.equal(typeof info.depth, 'number');
assert.equal(typeof info.decay, 'number');
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,34 @@
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
export function transformArguments(key: string): Array<string> {
return ['TOPK.INFO', key];
}
export type InfoRawReply = [
_: string,
k: number,
_: string,
width: number,
_: string,
depth: number,
_: string,
decay: string
];
export interface InfoReply {
k: number,
width: number;
depth: number;
decay: number;
}
export function transformReply(reply: InfoRawReply): InfoReply {
return {
k: reply[1],
width: reply[3],
depth: reply[5],
decay: Number(reply[7])
};
}

View File

@@ -0,0 +1,21 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../../test-utils';
import { transformArguments } from './LIST';
describe('TOPK LIST', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
['TOPK.LIST', 'key']
);
});
testUtils.testWithClient('client.topK.list', async client => {
await client.topK.reserve('key', 3);
assert.deepEqual(
await client.topK.list('key'),
[]
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,7 @@
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string): Array<string> {
return ['TOPK.LIST', key];
}
export declare function transformReply(): Array<string | null>;

View File

@@ -0,0 +1,21 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../../test-utils';
import { transformArguments } from './QUERY';
describe('TOPK QUERY', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', 'item'),
['TOPK.QUERY', 'key', 'item']
);
});
testUtils.testWithClient('client.cms.query', async client => {
await client.topK.reserve('key', 3);
assert.deepEqual(
await client.topK.query('key', 'item'),
[0]
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,15 @@
import { RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
import { pushVerdictArguments } from '@node-redis/client/dist/lib/commands/generic-transformers';
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
export function transformArguments(
key: string,
items: string | Array<string>
): RedisCommandArguments {
return pushVerdictArguments(['TOPK.QUERY', key], items);
}
export declare function transformReply(): Array<number>;

View File

@@ -0,0 +1,32 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../../test-utils';
import { transformArguments } from './RESERVE';
describe('TOPK RESERVE', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
transformArguments('topK', 3),
['TOPK.RESERVE', 'topK', '3']
);
});
it('with options', () => {
assert.deepEqual(
transformArguments('topK', 3, {
width: 8,
depth: 7,
decay: 0.9
}),
['TOPK.RESERVE', 'topK', '3', '8', '7', '0.9']
);
});
});
testUtils.testWithClient('client.topK.reserve', async client => {
assert.equal(
await client.topK.reserve('topK', 3),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,27 @@
export const FIRST_KEY_INDEX = 1;
interface ReserveOptions {
width: number;
depth: number;
decay: number;
}
export function transformArguments(
key: string,
topK: number,
options?: ReserveOptions
): Array<string> {
const args = ['TOPK.RESERVE', key, topK.toString()];
if (options) {
args.push(
options.width.toString(),
options.depth.toString(),
options.decay.toString()
);
}
return args;
}
export declare function transformReply(): 'OK';

View File

@@ -0,0 +1,24 @@
import * as ADD from './ADD';
import * as COUNT from './COUNT';
import * as INCRBY from './INCRBY';
import * as INFO from './INFO';
import * as LIST from './LIST';
import * as QUERY from './QUERY';
import * as RESERVE from './RESERVE';
export default {
ADD,
add: ADD,
COUNT,
count: COUNT,
INCRBY,
incrBy: INCRBY,
INFO,
info: INFO,
LIST,
list: LIST,
QUERY,
query: QUERY,
RESERVE,
reserve: RESERVE
};