You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
WIP
This commit is contained in:
23
benchmark/lib/ping/local-resp3-buffer-proxy.js
Normal file
23
benchmark/lib/ping/local-resp3-buffer-proxy.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { createClient, RESP_TYPES } from 'redis-local';
|
||||||
|
|
||||||
|
export default async (host) => {
|
||||||
|
const client = createClient({
|
||||||
|
socket: {
|
||||||
|
host
|
||||||
|
},
|
||||||
|
RESP: 3
|
||||||
|
}).withTypeMapping({
|
||||||
|
[RESP_TYPES.SIMPLE_STRING]: Buffer
|
||||||
|
});
|
||||||
|
|
||||||
|
await client.connect();
|
||||||
|
|
||||||
|
return {
|
||||||
|
benchmark() {
|
||||||
|
return client.ping();
|
||||||
|
},
|
||||||
|
teardown() {
|
||||||
|
return client.disconnect();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
24
benchmark/lib/ping/local-resp3-buffer.js
Normal file
24
benchmark/lib/ping/local-resp3-buffer.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { createClient, RESP_TYPES } from 'redis-local';
|
||||||
|
|
||||||
|
export default async (host) => {
|
||||||
|
const client = createClient({
|
||||||
|
socket: {
|
||||||
|
host
|
||||||
|
},
|
||||||
|
commandOptions: {
|
||||||
|
[RESP_TYPES.SIMPLE_STRING]: Buffer
|
||||||
|
},
|
||||||
|
RESP: 3
|
||||||
|
});
|
||||||
|
|
||||||
|
await client.connect();
|
||||||
|
|
||||||
|
return {
|
||||||
|
benchmark() {
|
||||||
|
return client.ping();
|
||||||
|
},
|
||||||
|
teardown() {
|
||||||
|
return client.disconnect();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
@@ -73,11 +73,11 @@ const benchmarkStart = process.hrtime.bigint(),
|
|||||||
json = {
|
json = {
|
||||||
// timestamp,
|
// timestamp,
|
||||||
operationsPerSecond: times / Number(benchmarkNanoseconds) * 1_000_000_000,
|
operationsPerSecond: times / Number(benchmarkNanoseconds) * 1_000_000_000,
|
||||||
// p0: histogram.getValueAtPercentile(0),
|
p0: histogram.getValueAtPercentile(0),
|
||||||
// p50: histogram.getValueAtPercentile(50),
|
p50: histogram.getValueAtPercentile(50),
|
||||||
// p95: histogram.getValueAtPercentile(95),
|
p95: histogram.getValueAtPercentile(95),
|
||||||
// p99: histogram.getValueAtPercentile(99),
|
p99: histogram.getValueAtPercentile(99),
|
||||||
// p100: histogram.getValueAtPercentile(100)
|
p100: histogram.getValueAtPercentile(100)
|
||||||
};
|
};
|
||||||
console.log(`[${basename(path)}]:`);
|
console.log(`[${basename(path)}]:`);
|
||||||
console.table(json);
|
console.table(json);
|
||||||
|
@@ -177,6 +177,10 @@ Some command arguments/replies have changed to align more closely to data types
|
|||||||
- `FT.SUGDEL`: [^boolean-to-number]
|
- `FT.SUGDEL`: [^boolean-to-number]
|
||||||
- `TOPK.QUERY`: `Array<number>` -> `Array<boolean>`
|
- `TOPK.QUERY`: `Array<number>` -> `Array<boolean>`
|
||||||
- `GRAPH.SLOWLOG`: `timestamp` has been changed from `Date` to `number`
|
- `GRAPH.SLOWLOG`: `timestamp` has been changed from `Date` to `number`
|
||||||
|
- `JSON.ARRINDEX`: `start` and `end` arguments moved to `{ range: { start: number; end: number; }; }` [^future-proofing]
|
||||||
|
- `JSON.ARRLEN`: `path` argument moved to `{ path: string; }` [^future-proofing]
|
||||||
|
- `JSON.DEL`: `path` argument moved to `{ path: string; }` [^future-proofing]
|
||||||
|
- `JSON.FORGET`: `path` argument moved to `{ path: string; }` [^future-proofing]
|
||||||
|
|
||||||
[^enum-to-constants]: TODO
|
[^enum-to-constants]: TODO
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { RedisArgument, TuplesReply, NumberReply, BlobStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, TuplesReply, NumberReply, BlobStringReply, UnwrapReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
@@ -6,7 +6,7 @@ export default {
|
|||||||
transformArguments(key: RedisArgument, iterator: number) {
|
transformArguments(key: RedisArgument, iterator: number) {
|
||||||
return ['BF.SCANDUMP', key, iterator.toString()];
|
return ['BF.SCANDUMP', key, iterator.toString()];
|
||||||
},
|
},
|
||||||
transformReply(reply: TuplesReply<[NumberReply, BlobStringReply]>) {
|
transformReply(reply: UnwrapReply<TuplesReply<[NumberReply, BlobStringReply]>>) {
|
||||||
return {
|
return {
|
||||||
iterator: reply[0],
|
iterator: reply[0],
|
||||||
chunk: reply[1]
|
chunk: reply[1]
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { RedisArgument, TuplesToMapReply, BlobStringReply, NumberReply, Resp2Reply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, TuplesToMapReply, BlobStringReply, NumberReply, UnwrapReply, Resp2Reply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
export type BfInfoReply = TuplesToMapReply<[
|
export type BfInfoReply = TuplesToMapReply<[
|
||||||
[BlobStringReply<'width'>, NumberReply],
|
[BlobStringReply<'width'>, NumberReply],
|
||||||
@@ -13,7 +13,7 @@ export default {
|
|||||||
return ['CMS.INFO', key];
|
return ['CMS.INFO', key];
|
||||||
},
|
},
|
||||||
transformReply: {
|
transformReply: {
|
||||||
2: (reply: Resp2Reply<BfInfoReply>) => ({
|
2: (reply: UnwrapReply<Resp2Reply<BfInfoReply>>) => ({
|
||||||
width: reply[1],
|
width: reply[1],
|
||||||
depth: reply[3],
|
depth: reply[3],
|
||||||
count: reply[5]
|
count: reply[5]
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { RedisArgument, TuplesReply, NumberReply, BlobStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, TuplesReply, NumberReply, BlobStringReply, NullReply, UnwrapReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
@@ -6,7 +6,7 @@ export default {
|
|||||||
transformArguments(key: RedisArgument, iterator: number) {
|
transformArguments(key: RedisArgument, iterator: number) {
|
||||||
return ['CF.SCANDUMP', key, iterator.toString()];
|
return ['CF.SCANDUMP', key, iterator.toString()];
|
||||||
},
|
},
|
||||||
transformReply(reply: TuplesReply<[NumberReply, BlobStringReply | NullReply]>) {
|
transformReply(reply: UnwrapReply<TuplesReply<[NumberReply, BlobStringReply | NullReply]>>) {
|
||||||
return {
|
return {
|
||||||
iterator: reply[0],
|
iterator: reply[0],
|
||||||
chunk: reply[1]
|
chunk: reply[1]
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { RedisArgument, TuplesToMapReply, BlobStringReply, NumberReply, DoubleReply, Resp2Reply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, TuplesToMapReply, BlobStringReply, NumberReply, DoubleReply, UnwrapReply, Resp2Reply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
export type TopKInfoReply = TuplesToMapReply<[
|
export type TopKInfoReply = TuplesToMapReply<[
|
||||||
[BlobStringReply<'k'>, NumberReply],
|
[BlobStringReply<'k'>, NumberReply],
|
||||||
@@ -14,7 +14,7 @@ export default {
|
|||||||
return ['TOPK.INFO', key];
|
return ['TOPK.INFO', key];
|
||||||
},
|
},
|
||||||
transformReply: {
|
transformReply: {
|
||||||
2: (reply: Resp2Reply<TopKInfoReply>) => ({
|
2: (reply: UnwrapReply<Resp2Reply<TopKInfoReply>>) => ({
|
||||||
k: reply[1],
|
k: reply[1],
|
||||||
width: reply[3],
|
width: reply[3],
|
||||||
depth: reply[5],
|
depth: reply[5],
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { RedisArgument, ArrayReply, SimpleStringReply, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, ArrayReply, SimpleStringReply, NumberReply, UnwrapReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
@@ -6,11 +6,11 @@ export default {
|
|||||||
transformArguments(key: RedisArgument) {
|
transformArguments(key: RedisArgument) {
|
||||||
return ['TOPK.LIST', key, 'WITHCOUNT'];
|
return ['TOPK.LIST', key, 'WITHCOUNT'];
|
||||||
},
|
},
|
||||||
transformReply(rawReply: ArrayReply<SimpleStringReply | NumberReply>) {
|
transformReply(rawReply: UnwrapReply<ArrayReply<SimpleStringReply | NumberReply>>) {
|
||||||
const reply = [] as unknown as ArrayReply<{
|
const reply: Array<{
|
||||||
item: SimpleStringReply;
|
item: SimpleStringReply;
|
||||||
count: NumberReply;
|
count: NumberReply;
|
||||||
}>;
|
}> = [];
|
||||||
|
|
||||||
for (let i = 0; i < rawReply.length; i++) {
|
for (let i = 0; i < rawReply.length; i++) {
|
||||||
reply.push({
|
reply.push({
|
||||||
|
@@ -20,11 +20,11 @@ describe('ARRAPPEND', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.json.arrAppend', async client => {
|
testUtils.testWithClient('client.json.arrAppend', async client => {
|
||||||
await client.json.set('key', '$', []);
|
const [, reply] = await Promise.all([
|
||||||
|
client.json.set('key', '$', []),
|
||||||
|
client.json.arrAppend('key', '$', 1)
|
||||||
|
]);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(reply, [1]);
|
||||||
await client.json.arrAppend('key', '$', 1),
|
|
||||||
[1]
|
|
||||||
);
|
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
@@ -13,5 +13,5 @@ export default {
|
|||||||
|
|
||||||
return args;
|
return args;
|
||||||
},
|
},
|
||||||
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
|
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||||
} as const satisfies Command;
|
} as const satisfies Command;
|
||||||
|
@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
|
|||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import ARRINDEX from './ARRINDEX';
|
import ARRINDEX from './ARRINDEX';
|
||||||
|
|
||||||
describe('ARRINDEX', () => {
|
describe('JSON.ARRINDEX', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('simple', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
@@ -11,27 +11,39 @@ describe('ARRINDEX', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('with start', () => {
|
|
||||||
|
describe('with range', () => {
|
||||||
|
it('start only', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
ARRINDEX.transformArguments('key', '$', 'json', 1),
|
ARRINDEX.transformArguments('key', '$', 'json', {
|
||||||
['JSON.ARRINDEX', 'key', '$', '"json"', '1']
|
range: {
|
||||||
|
start: 0
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
['JSON.ARRINDEX', 'key', '$', '"json"', '0']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('with start, end', () => {
|
it('with start and stop', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
ARRINDEX.transformArguments('key', '$', 'json', 1, 2),
|
ARRINDEX.transformArguments('key', '$', 'json', {
|
||||||
['JSON.ARRINDEX', 'key', '$', '"json"', '1', '2']
|
range: {
|
||||||
|
start: 0,
|
||||||
|
stop: 1
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
['JSON.ARRINDEX', 'key', '$', '"json"', '0', '1']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.json.arrIndex', async client => {
|
testUtils.testWithClient('client.json.arrIndex', async client => {
|
||||||
await client.json.set('key', '$', []);
|
const [, reply] = await Promise.all([
|
||||||
|
client.json.set('key', '$', []),
|
||||||
|
client.json.arrIndex('key', '$', 'json')
|
||||||
|
]);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(reply, [-1]);
|
||||||
await client.json.arrIndex('key', '$', 'json'),
|
|
||||||
[-1]
|
|
||||||
);
|
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -1,6 +1,13 @@
|
|||||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||||
|
|
||||||
|
export interface JsonArrIndexOptions {
|
||||||
|
range?: {
|
||||||
|
start: number;
|
||||||
|
stop?: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: true,
|
IS_READ_ONLY: true,
|
||||||
@@ -8,20 +15,19 @@ export default {
|
|||||||
key: RedisArgument,
|
key: RedisArgument,
|
||||||
path: RedisArgument,
|
path: RedisArgument,
|
||||||
json: RedisJSON,
|
json: RedisJSON,
|
||||||
start?: number,
|
options?: JsonArrIndexOptions
|
||||||
stop?: number
|
|
||||||
) {
|
) {
|
||||||
const args = ['JSON.ARRINDEX', key, path, transformRedisJsonArgument(json)];
|
const args = ['JSON.ARRINDEX', key, path, transformRedisJsonArgument(json)];
|
||||||
|
|
||||||
if (start !== undefined && start !== null) {
|
if (options?.range) {
|
||||||
args.push(start.toString());
|
args.push(options.range.start.toString());
|
||||||
|
|
||||||
if (stop !== undefined && stop !== null) {
|
if (options.range.stop !== undefined) {
|
||||||
args.push(stop.toString());
|
args.push(options.range.stop.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
},
|
},
|
||||||
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
|
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||||
} as const satisfies Command;
|
} as const satisfies Command;
|
||||||
|
@@ -20,11 +20,11 @@ describe('JSON.ARRINSERT', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.json.arrInsert', async client => {
|
testUtils.testWithClient('client.json.arrInsert', async client => {
|
||||||
await client.json.set('key', '$', []);
|
const [, reply] = await Promise.all([
|
||||||
|
client.json.set('key', '$', []),
|
||||||
|
client.json.arrInsert('key', '$', 0, 'json')
|
||||||
|
]);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(reply, [1]);
|
||||||
await client.json.arrInsert('key', '$', 0, 'json'),
|
|
||||||
[1]
|
|
||||||
);
|
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -1,11 +1,23 @@
|
|||||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: false,
|
||||||
transformArguments(key: RedisArgument, path: RedisArgument, index: number, ...jsons: Array<RedisJSON>) {
|
transformArguments(
|
||||||
const args = ['JSON.ARRINSERT', key, path, index.toString()];
|
key: RedisArgument,
|
||||||
|
path: RedisArgument,
|
||||||
|
index: number,
|
||||||
|
json: RedisJSON,
|
||||||
|
...jsons: Array<RedisJSON>
|
||||||
|
) {
|
||||||
|
const args = [
|
||||||
|
'JSON.ARRINSERT',
|
||||||
|
key,
|
||||||
|
path,
|
||||||
|
index.toString(),
|
||||||
|
transformRedisJsonArgument(json)
|
||||||
|
];
|
||||||
|
|
||||||
for (const json of jsons) {
|
for (const json of jsons) {
|
||||||
args.push(transformRedisJsonArgument(json));
|
args.push(transformRedisJsonArgument(json));
|
||||||
@@ -13,5 +25,5 @@ export default {
|
|||||||
|
|
||||||
return args;
|
return args;
|
||||||
},
|
},
|
||||||
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
|
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||||
} as const satisfies Command;
|
} as const satisfies Command;
|
||||||
|
@@ -4,7 +4,7 @@ import ARRLEN from './ARRLEN';
|
|||||||
|
|
||||||
describe('JSON.ARRLEN', () => {
|
describe('JSON.ARRLEN', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('without path', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
ARRLEN.transformArguments('key'),
|
ARRLEN.transformArguments('key'),
|
||||||
['JSON.ARRLEN', 'key']
|
['JSON.ARRLEN', 'key']
|
||||||
@@ -13,18 +13,20 @@ describe('JSON.ARRLEN', () => {
|
|||||||
|
|
||||||
it('with path', () => {
|
it('with path', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
ARRLEN.transformArguments('key', '$'),
|
ARRLEN.transformArguments('key', {
|
||||||
|
path: '$'
|
||||||
|
}),
|
||||||
['JSON.ARRLEN', 'key', '$']
|
['JSON.ARRLEN', 'key', '$']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.json.arrLen', async client => {
|
testUtils.testWithClient('client.json.arrLen', async client => {
|
||||||
await client.json.set('key', '$', []);
|
const [, reply] = await Promise.all([
|
||||||
|
client.json.set('key', '$', []),
|
||||||
|
client.json.arrLen('key')
|
||||||
|
]);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(reply, 0);
|
||||||
await client.json.arrLen('key', '$'),
|
|
||||||
[0]
|
|
||||||
);
|
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -1,16 +1,20 @@
|
|||||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
|
export interface JsonArrLenOptions {
|
||||||
|
path?: RedisArgument;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: true,
|
IS_READ_ONLY: true,
|
||||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
transformArguments(key: RedisArgument, options?: JsonArrLenOptions) {
|
||||||
const args = ['JSON.ARRLEN', key];
|
const args = ['JSON.ARRLEN', key];
|
||||||
|
|
||||||
if (path) {
|
if (options?.path) {
|
||||||
args.push(path);
|
args.push(options.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
},
|
},
|
||||||
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
|
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||||
} as const satisfies Command;
|
} as const satisfies Command;
|
||||||
|
@@ -11,11 +11,11 @@ describe('JSON.ARRTRIM', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.json.arrTrim', async client => {
|
testUtils.testWithClient('client.json.arrTrim', async client => {
|
||||||
await client.json.set('key', '$', []);
|
const [, reply] = await Promise.all([
|
||||||
|
client.json.set('key', '$', []),
|
||||||
|
client.json.arrTrim('key', '$', 0, 1)
|
||||||
|
]);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(reply, [0]);
|
||||||
await client.json.arrTrim('key', '$', 0, 1),
|
|
||||||
[0]
|
|
||||||
);
|
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -6,5 +6,5 @@ export default {
|
|||||||
transformArguments(key: RedisArgument, path: RedisArgument, start: number, stop: number) {
|
transformArguments(key: RedisArgument, path: RedisArgument, start: number, stop: number) {
|
||||||
return ['JSON.ARRTRIM', key, path, start.toString(), stop.toString()];
|
return ['JSON.ARRTRIM', key, path, start.toString(), stop.toString()];
|
||||||
},
|
},
|
||||||
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
|
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||||
} as const satisfies Command;
|
} as const satisfies Command;
|
||||||
|
@@ -4,17 +4,19 @@ import CLEAR from './CLEAR';
|
|||||||
|
|
||||||
describe('JSON.CLEAR', () => {
|
describe('JSON.CLEAR', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('key', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
CLEAR.transformArguments('key'),
|
CLEAR.transformArguments('key'),
|
||||||
['JSON.CLEAR', 'key']
|
['JSON.CLEAR', 'key']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('key, path', () => {
|
it('with path', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
CLEAR.transformArguments('key', '$.path'),
|
CLEAR.transformArguments('key', {
|
||||||
['JSON.CLEAR', 'key', '$.path']
|
path: '$'
|
||||||
|
}),
|
||||||
|
['JSON.CLEAR', 'key', '$']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,12 +1,18 @@
|
|||||||
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
|
export interface JsonClearOptions {
|
||||||
|
path?: RedisArgument;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: false,
|
||||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
transformArguments(key: RedisArgument, options?: JsonClearOptions) {
|
||||||
const args = ['JSON.CLEAR', key];
|
const args = ['JSON.CLEAR', key];
|
||||||
|
|
||||||
if (path) args.push(path);
|
if (options?.path) {
|
||||||
|
args.push(options.path);
|
||||||
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
},
|
},
|
||||||
|
@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
|
|||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import DEBUG_MEMORY from './DEBUG_MEMORY';
|
import DEBUG_MEMORY from './DEBUG_MEMORY';
|
||||||
|
|
||||||
describe('DEBUG MEMORY', () => {
|
describe('JSON.DEBUG MEMORY', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('without path', () => {
|
it('without path', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
@@ -19,10 +19,10 @@ describe('DEBUG MEMORY', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.json.arrTrim', async client => {
|
testUtils.testWithClient('client.json.debugMemory', async client => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
await client.json.debugMemory('key', '$'),
|
await client.json.debugMemory('key', '$'),
|
||||||
[]
|
0
|
||||||
);
|
);
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, NumberReply, ArrayReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 2,
|
FIRST_KEY_INDEX: 2,
|
||||||
|
@@ -2,18 +2,20 @@ import { strict as assert } from 'assert';
|
|||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import DEL from './DEL';
|
import DEL from './DEL';
|
||||||
|
|
||||||
describe('DEL', () => {
|
describe('JSON.DEL', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('key', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
DEL.transformArguments('key'),
|
DEL.transformArguments('key'),
|
||||||
['JSON.DEL', 'key']
|
['JSON.DEL', 'key']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('key, path', () => {
|
it('with path', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
DEL.transformArguments('key', '$.path'),
|
DEL.transformArguments('key', {
|
||||||
|
path: '$.path'
|
||||||
|
}),
|
||||||
['JSON.DEL', 'key', '$.path']
|
['JSON.DEL', 'key', '$.path']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -1,13 +1,17 @@
|
|||||||
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
|
export interface JsonDelOptions {
|
||||||
|
path?: RedisArgument
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: false,
|
||||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
transformArguments(key: RedisArgument, options?: JsonDelOptions) {
|
||||||
const args = ['JSON.DEL', key];
|
const args = ['JSON.DEL', key];
|
||||||
|
|
||||||
if (path) {
|
if (options?.path) {
|
||||||
args.push(path);
|
args.push(options.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
|
@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
|
|||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import FORGET from './FORGET';
|
import FORGET from './FORGET';
|
||||||
|
|
||||||
describe('FORGET', () => {
|
describe('JSON.FORGET', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('key', () => {
|
it('key', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
@@ -13,7 +13,9 @@ describe('FORGET', () => {
|
|||||||
|
|
||||||
it('key, path', () => {
|
it('key, path', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
FORGET.transformArguments('key', '$.path'),
|
FORGET.transformArguments('key', {
|
||||||
|
path: '$.path'
|
||||||
|
}),
|
||||||
['JSON.FORGET', 'key', '$.path']
|
['JSON.FORGET', 'key', '$.path']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -1,13 +1,17 @@
|
|||||||
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
|
export interface JsonForgetOptions {
|
||||||
|
path?: RedisArgument;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: false,
|
||||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
transformArguments(key: RedisArgument, options?: JsonForgetOptions) {
|
||||||
const args = ['JSON.FORGET', key];
|
const args = ['JSON.FORGET', key];
|
||||||
|
|
||||||
if (path) {
|
if (options?.path) {
|
||||||
args.push(path);
|
args.push(options.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
|
@@ -1,42 +1,42 @@
|
|||||||
import { pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
|
// import { pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||||
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
|
// import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
|
||||||
|
|
||||||
export const FIRST_KEY_INDEX = 1;
|
// export const FIRST_KEY_INDEX = 1;
|
||||||
|
|
||||||
export const IS_READ_ONLY = true;
|
// export const IS_READ_ONLY = true;
|
||||||
|
|
||||||
interface GetOptions {
|
// interface GetOptions {
|
||||||
path?: string | Array<string>;
|
// path?: string | Array<string>;
|
||||||
INDENT?: string;
|
// INDENT?: string;
|
||||||
NEWLINE?: string;
|
// NEWLINE?: string;
|
||||||
SPACE?: string;
|
// SPACE?: string;
|
||||||
NOESCAPE?: true;
|
// NOESCAPE?: true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
export function transformArguments(key: string, options?: GetOptions): RedisCommandArguments {
|
// export function transformArguments(key: string, options?: GetOptions): RedisCommandArguments {
|
||||||
let args: RedisCommandArguments = ['JSON.GET', key];
|
// let args: RedisCommandArguments = ['JSON.GET', key];
|
||||||
|
|
||||||
if (options?.path) {
|
// if (options?.path) {
|
||||||
args = pushVariadicArguments(args, options.path);
|
// args = pushVariadicArguments(args, options.path);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (options?.INDENT) {
|
// if (options?.INDENT) {
|
||||||
args.push('INDENT', options.INDENT);
|
// args.push('INDENT', options.INDENT);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (options?.NEWLINE) {
|
// if (options?.NEWLINE) {
|
||||||
args.push('NEWLINE', options.NEWLINE);
|
// args.push('NEWLINE', options.NEWLINE);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (options?.SPACE) {
|
// if (options?.SPACE) {
|
||||||
args.push('SPACE', options.SPACE);
|
// args.push('SPACE', options.SPACE);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (options?.NOESCAPE) {
|
// if (options?.NOESCAPE) {
|
||||||
args.push('NOESCAPE');
|
// args.push('NOESCAPE');
|
||||||
}
|
// }
|
||||||
|
|
||||||
return args;
|
// return args;
|
||||||
}
|
// }
|
||||||
|
|
||||||
export { transformRedisJsonNullReply as transformReply } from '.';
|
// export { transformRedisJsonNullReply as transformReply } from '.';
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { RedisArgument, Command, ArrayReply, NumberReply, DoubleReply, NullReply } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, NumberReply, DoubleReply, NullReply, BlobStringReply, UnwrapReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
@@ -6,5 +6,10 @@ export default {
|
|||||||
transformArguments(key: RedisArgument, path: RedisArgument, by: number) {
|
transformArguments(key: RedisArgument, path: RedisArgument, by: number) {
|
||||||
return ['JSON.NUMINCRBY', key, path, by.toString()];
|
return ['JSON.NUMINCRBY', key, path, by.toString()];
|
||||||
},
|
},
|
||||||
transformReply: undefined as unknown as () => ArrayReply<NumberReply | DoubleReply | NullReply>
|
transformReply: {
|
||||||
|
2: (reply: UnwrapReply<BlobStringReply>) => {
|
||||||
|
return JSON.parse(reply.toString()) as number | Array<number>;
|
||||||
|
},
|
||||||
|
3: undefined as unknown as () => NumberReply | DoubleReply | NullReply
|
||||||
|
}
|
||||||
} as const satisfies Command;
|
} as const satisfies Command;
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
import { RedisArgument, ArrayReply, BlobStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, ArrayReply, BlobStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
type ReplyItem = ArrayReply<BlobStringReply> | NullReply;
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: false,
|
||||||
@@ -14,5 +12,5 @@ export default {
|
|||||||
|
|
||||||
return args;
|
return args;
|
||||||
},
|
},
|
||||||
transformReply: undefined as unknown as () => ReplyItem | ArrayReply<ReplyItem>
|
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply> | ArrayReply<ArrayReply<BlobStringReply> | NullReply>
|
||||||
} as const satisfies Command;
|
} as const satisfies Command;
|
||||||
|
@@ -19,10 +19,10 @@ describe('JSON.OBJLEN', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// testUtils.testWithClient('client.json.objLen', async client => {
|
testUtils.testWithClient('client.json.objLen', async client => {
|
||||||
// assert.equal(
|
assert.equal(
|
||||||
// await client.json.objLen('key', '$'),
|
await client.json.objLen('key', '$'),
|
||||||
// [null]
|
[null]
|
||||||
// );
|
);
|
||||||
// }, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: true,
|
||||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
||||||
const args = ['JSON.OBJLEN', key];
|
const args = ['JSON.OBJLEN', key];
|
||||||
|
|
||||||
@@ -12,5 +12,5 @@ export default {
|
|||||||
|
|
||||||
return args;
|
return args;
|
||||||
},
|
},
|
||||||
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
|
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||||
} as const satisfies Command;
|
} as const satisfies Command;
|
||||||
|
@@ -19,3 +19,14 @@
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// export declare function transformReply(): number | Array<number>;
|
// export declare function transformReply(): number | Array<number>;
|
||||||
|
|
||||||
|
import { SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
FIRST_KEY_INDEX: 1,
|
||||||
|
IS_READ_ONLY: false,
|
||||||
|
transformArguments() {
|
||||||
|
return ['JSON.STRAPPEND'];
|
||||||
|
},
|
||||||
|
transformReply: undefined as unknown as () => SimpleStringReply
|
||||||
|
} as const satisfies Command;
|
||||||
|
@@ -20,11 +20,11 @@ describe('JSON.STRLEN', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.json.strLen', async client => {
|
testUtils.testWithClient('client.json.strLen', async client => {
|
||||||
await client.json.set('key', '$', '');
|
const [, reply] = await Promise.all([
|
||||||
|
client.json.set('key', '$', ''),
|
||||||
|
client.json.strLen('key', '$')
|
||||||
|
]);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(reply, [0]);
|
||||||
await client.json.strLen('key', '$'),
|
|
||||||
[0]
|
|
||||||
);
|
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -12,5 +12,5 @@ export default {
|
|||||||
|
|
||||||
return args;
|
return args;
|
||||||
},
|
},
|
||||||
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
|
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||||
} as const satisfies Command;
|
} as const satisfies Command;
|
||||||
|
@@ -20,11 +20,11 @@ describe('JSON.TOGGLE', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.json.toggle', async client => {
|
testUtils.testWithClient('client.json.toggle', async client => {
|
||||||
await client.json.set('key', '$', '');
|
const [, reply] = await Promise.all([
|
||||||
|
client.json.set('key', '$', ''),
|
||||||
|
client.json.toggle('key', '$')
|
||||||
|
]);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(reply, [0]);
|
||||||
await client.json.toggle('key', '$'),
|
|
||||||
[0]
|
|
||||||
);
|
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -1,12 +1,14 @@
|
|||||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command, } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command, } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: undefined,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: false,
|
||||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
||||||
const args = ['JSON.TOGGLE', key]
|
const args = ['JSON.TOGGLE', key]
|
||||||
|
|
||||||
if (path) args.push(path);
|
if (path) {
|
||||||
|
args.push(path);
|
||||||
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
},
|
},
|
||||||
|
@@ -1,24 +1,25 @@
|
|||||||
import * as ARRAPPEND from './ARRAPPEND';
|
import ARRAPPEND from './ARRAPPEND';
|
||||||
import * as ARRINDEX from './ARRINDEX';
|
import ARRINDEX from './ARRINDEX';
|
||||||
import * as ARRINSERT from './ARRINSERT';
|
import ARRINSERT from './ARRINSERT';
|
||||||
import CLEAR from './CLEAR';
|
import CLEAR from './CLEAR';
|
||||||
import * as ARRLEN from './ARRLEN';
|
import ARRLEN from './ARRLEN';
|
||||||
import * as ARRPOP from './ARRPOP';
|
// import ARRPOP from './ARRPOP';
|
||||||
import * as ARRTRIM from './ARRTRIM';
|
import ARRTRIM from './ARRTRIM';
|
||||||
import * as DEBUG_MEMORY from './DEBUG_MEMORY';
|
import DEBUG_MEMORY from './DEBUG_MEMORY';
|
||||||
import * as DEL from './DEL';
|
import DEL from './DEL';
|
||||||
import * as FORGET from './FORGET';
|
import FORGET from './FORGET';
|
||||||
import * as GET from './GET';
|
// import GET from './GET';
|
||||||
import * as MGET from './MGET';
|
// import MGET from './MGET';
|
||||||
import * as NUMINCRBY from './NUMINCRBY';
|
import NUMINCRBY from './NUMINCRBY';
|
||||||
import * as NUMMULTBY from './NUMMULTBY';
|
import NUMMULTBY from './NUMMULTBY';
|
||||||
import * as OBJKEYS from './OBJKEYS';
|
import OBJKEYS from './OBJKEYS';
|
||||||
import * as OBJLEN from './OBJLEN';
|
import OBJLEN from './OBJLEN';
|
||||||
import * as RESP from './RESP';
|
// import RESP from './RESP';
|
||||||
import * as SET from './SET';
|
import SET from './SET';
|
||||||
import * as STRAPPEND from './STRAPPEND';
|
import STRAPPEND from './STRAPPEND';
|
||||||
import * as STRLEN from './STRLEN';
|
import STRLEN from './STRLEN';
|
||||||
import * as TYPE from './TYPE';
|
import TOGGLE from './TOGGLE';
|
||||||
|
// import TYPE from './TYPE';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
ARRAPPEND,
|
ARRAPPEND,
|
||||||
@@ -31,8 +32,8 @@ export default {
|
|||||||
clear: CLEAR,
|
clear: CLEAR,
|
||||||
ARRLEN,
|
ARRLEN,
|
||||||
arrLen: ARRLEN,
|
arrLen: ARRLEN,
|
||||||
ARRPOP,
|
// ARRPOP,
|
||||||
arrPop: ARRPOP,
|
// arrPop: ARRPOP,
|
||||||
ARRTRIM,
|
ARRTRIM,
|
||||||
arrTrim: ARRTRIM,
|
arrTrim: ARRTRIM,
|
||||||
DEBUG_MEMORY,
|
DEBUG_MEMORY,
|
||||||
@@ -41,10 +42,10 @@ export default {
|
|||||||
del: DEL,
|
del: DEL,
|
||||||
FORGET,
|
FORGET,
|
||||||
forget: FORGET,
|
forget: FORGET,
|
||||||
GET,
|
// GET,
|
||||||
get: GET,
|
// get: GET,
|
||||||
MGET,
|
// MGET,
|
||||||
mGet: MGET,
|
// mGet: MGET,
|
||||||
NUMINCRBY,
|
NUMINCRBY,
|
||||||
numIncrBy: NUMINCRBY,
|
numIncrBy: NUMINCRBY,
|
||||||
NUMMULTBY,
|
NUMMULTBY,
|
||||||
@@ -53,21 +54,23 @@ export default {
|
|||||||
objKeys: OBJKEYS,
|
objKeys: OBJKEYS,
|
||||||
OBJLEN,
|
OBJLEN,
|
||||||
objLen: OBJLEN,
|
objLen: OBJLEN,
|
||||||
RESP,
|
// RESP,
|
||||||
resp: RESP,
|
// resp: RESP,
|
||||||
SET,
|
SET,
|
||||||
set: SET,
|
set: SET,
|
||||||
STRAPPEND,
|
STRAPPEND,
|
||||||
strAppend: STRAPPEND,
|
strAppend: STRAPPEND,
|
||||||
STRLEN,
|
STRLEN,
|
||||||
strLen: STRLEN,
|
strLen: STRLEN,
|
||||||
TYPE,
|
TOGGLE,
|
||||||
type: TYPE
|
toggle: TOGGLE,
|
||||||
|
// TYPE,
|
||||||
|
// type: TYPE
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||||
interface RedisJSONArray extends Array<RedisJSON> {}
|
interface RedisJSONArray extends Array<RedisJSON> { }
|
||||||
interface RedisJSONObject {
|
interface RedisJSONObject {
|
||||||
[key: string]: RedisJSON;
|
[key: string]: RedisJSON;
|
||||||
[key: number]: RedisJSON;
|
[key: number]: RedisJSON;
|
||||||
|
11
packages/json/test.js
Normal file
11
packages/json/test.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { createClient } from '@redis/client';
|
||||||
|
import RedisJSON from '.';
|
||||||
|
|
||||||
|
const client = createClient({
|
||||||
|
modules: {
|
||||||
|
json: RedisJSON,
|
||||||
|
JSON: RedisJSON
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
client.JSON.
|
@@ -1,4 +1,4 @@
|
|||||||
import { RedisArgument, TuplesReply, NumberReply, DoubleReply, Resp2Reply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, TuplesReply, NumberReply, DoubleReply, UnwrapReply, Resp2Reply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
export interface TsGetOptions {
|
export interface TsGetOptions {
|
||||||
LATEST?: boolean;
|
LATEST?: boolean;
|
||||||
@@ -19,13 +19,13 @@ export default {
|
|||||||
return args;
|
return args;
|
||||||
},
|
},
|
||||||
transformReply: {
|
transformReply: {
|
||||||
2(reply: Resp2Reply<TsGetReply>) {
|
2(reply: UnwrapReply<Resp2Reply<TsGetReply>>) {
|
||||||
return reply.length === 0 ? null : {
|
return reply.length === 0 ? null : {
|
||||||
timestamp: reply[0],
|
timestamp: reply[0],
|
||||||
value: Number(reply[1])
|
value: Number(reply[1])
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
3(reply: TsGetReply) {
|
3(reply: UnwrapReply<TsGetReply>) {
|
||||||
return reply.length === 0 ? null : {
|
return reply.length === 0 ? null : {
|
||||||
timestamp: reply[0],
|
timestamp: reply[0],
|
||||||
value: reply[1]
|
value: reply[1]
|
||||||
|
260
test.mjs
260
test.mjs
@@ -1,260 +0,0 @@
|
|||||||
// // // import { createClient } from './benchmark/node_modules/@redis/client/dist/index.js';
|
|
||||||
// // // import Redis from './benchmark/node_modules/ioredis/built/index.js';
|
|
||||||
// // // import { setTimeout } from 'node:timers/promises';
|
|
||||||
|
|
||||||
// // // const client = createClient();
|
|
||||||
// // // client.on('error', err => console.error(err));
|
|
||||||
|
|
||||||
// // // await client.connect();
|
|
||||||
|
|
||||||
// // // const io = new Redis({
|
|
||||||
// // // lazyConnect: true,
|
|
||||||
// // // enableAutoPipelining: true
|
|
||||||
// // // });
|
|
||||||
// // // await io.connect();
|
|
||||||
|
|
||||||
// // // const TIMES = 1_000;
|
|
||||||
|
|
||||||
// // // while (true) {
|
|
||||||
// // // await benchmark('redis', () => {
|
|
||||||
// // // const promises = [];
|
|
||||||
// // // for (let i = 0; i < TIMES; i++) {
|
|
||||||
// // // promises.push(client.ping());
|
|
||||||
// // // }
|
|
||||||
|
|
||||||
// // // return Promise.all(promises);
|
|
||||||
// // // });
|
|
||||||
|
|
||||||
// // // await benchmark('ioredis', () => {
|
|
||||||
// // // const promises = [];
|
|
||||||
// // // for (let i = 0; i < TIMES; i++) {
|
|
||||||
// // // promises.push(io.ping());
|
|
||||||
// // // }
|
|
||||||
|
|
||||||
// // // return Promise.all(promises);
|
|
||||||
// // // });
|
|
||||||
// // // }
|
|
||||||
|
|
||||||
// // // async function benchmark(name, fn) {
|
|
||||||
// // // const start = process.hrtime.bigint();
|
|
||||||
|
|
||||||
// // // await fn();
|
|
||||||
|
|
||||||
// // // const took = Number(process.hrtime.bigint() - start);
|
|
||||||
// // // console.log(took, name);
|
|
||||||
|
|
||||||
// // // console.log('Sleep');
|
|
||||||
// // // await setTimeout(1000);
|
|
||||||
// // // console.log('Continue');
|
|
||||||
// // // }
|
|
||||||
|
|
||||||
// import Redis from 'ioredis';
|
|
||||||
|
|
||||||
// const cluster = new Redis.Cluster([{
|
|
||||||
// port: 6379,
|
|
||||||
// host: "127.0.0.1",
|
|
||||||
// }]);
|
|
||||||
|
|
||||||
// setInterval(() => {
|
|
||||||
// let i = 0;
|
|
||||||
// cluster.on('node-', () => {
|
|
||||||
// if (++3) {
|
|
||||||
// cluster.refreshSlotsCache(err => {
|
|
||||||
// console.log('done', err);
|
|
||||||
// });
|
|
||||||
// i = 0;
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// }, 5000);
|
|
||||||
|
|
||||||
// import { createCluster } from './packages/client/dist/index.js';
|
|
||||||
// import { setTimeout } from 'node:timers/promises';
|
|
||||||
|
|
||||||
// const cluster = createCluster({
|
|
||||||
// rootNodes: [{}]
|
|
||||||
// });
|
|
||||||
|
|
||||||
// cluster.on('error', err => console.error(err));
|
|
||||||
|
|
||||||
// await cluster.connect();
|
|
||||||
|
|
||||||
// console.log(
|
|
||||||
// await Promise.all([
|
|
||||||
// cluster.ping(),
|
|
||||||
// cluster.ping(),
|
|
||||||
// cluster.set('1', '1'),
|
|
||||||
// cluster.get('1'),
|
|
||||||
// cluster.get('2'),
|
|
||||||
// cluster.multi().ping().ping().get('a').set('a', 'b').get('a').execTyped()
|
|
||||||
// // cluster
|
|
||||||
// ])
|
|
||||||
// );
|
|
||||||
|
|
||||||
// import { createClient } from './packages/client/dist/index.js';
|
|
||||||
|
|
||||||
// const client = createClient();
|
|
||||||
|
|
||||||
// client.a();
|
|
||||||
|
|
||||||
// client.on('error', err => console.error('Redis Client Error', err));
|
|
||||||
|
|
||||||
// await client.connect();
|
|
||||||
|
|
||||||
// const legacy = client.legacy();
|
|
||||||
|
|
||||||
// console.log(
|
|
||||||
// await client.multi()
|
|
||||||
// .ping()
|
|
||||||
// .ping()
|
|
||||||
// .aaa()
|
|
||||||
// .exec(),
|
|
||||||
// await client.multi()
|
|
||||||
// .ping()
|
|
||||||
// .ping()
|
|
||||||
// .execTyped()
|
|
||||||
// );
|
|
||||||
|
|
||||||
// legacy.multi()
|
|
||||||
// .ping()
|
|
||||||
// .ping()
|
|
||||||
// .sendCommand(['PING', 'LEIBALE'])
|
|
||||||
// .exec((err, replies) => {
|
|
||||||
// console.log(err, replies);
|
|
||||||
// client.destroy();
|
|
||||||
// })
|
|
||||||
|
|
||||||
// for (let i = 0; i < 100; i++) {
|
|
||||||
// const promises = [];
|
|
||||||
// for (let j = 0; j < 5; j++) {
|
|
||||||
// promises.push(client.sendCommand(['PING']));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// console.log(
|
|
||||||
// await Promise.all(promises)
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // // const I = 100,
|
|
||||||
// // // J = 1_000;
|
|
||||||
|
|
||||||
// // // for (let i = 0; i < I; i++) {
|
|
||||||
// // // const promises = new Array(J);
|
|
||||||
// // // for (let j = 0; j < J; j++) {
|
|
||||||
// // // promises[j] = client.ping();
|
|
||||||
// // // }
|
|
||||||
|
|
||||||
// // // await Promise.all(promises);
|
|
||||||
// // // }
|
|
||||||
|
|
||||||
// import { writeFile } from 'node:fs/promises';
|
|
||||||
|
|
||||||
// function gen() {
|
|
||||||
|
|
||||||
// const lines = [
|
|
||||||
// `// ${new Date().toJSON()}`,
|
|
||||||
// 'import * as B from "./b";',
|
|
||||||
// 'export default {'
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// for (let i = 0; i < 40000; i++) {
|
|
||||||
// lines.push(` ${i}: B,`);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// lines.push('} as const;');
|
|
||||||
|
|
||||||
// return lines.join('\n');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// await writeFile('./a.ts', gen());
|
|
||||||
|
|
||||||
// import { createClient } from '@redis/client';
|
|
||||||
|
|
||||||
// console.log(new Date().toJSON());
|
|
||||||
|
|
||||||
// const client = createClient({
|
|
||||||
// url: 'redis://default:VugDBHGYAectnTj25wmCCAuhPOu3xkhk@redis-11344.c240.us-east-1-3.ec2.cloud.redislabs.com:11344'
|
|
||||||
// });
|
|
||||||
|
|
||||||
// client.on('error', err => console.error('11111', err, new Date().toJSON()));
|
|
||||||
|
|
||||||
// await client.connect();
|
|
||||||
|
|
||||||
// const client2 = createClient({
|
|
||||||
// url: 'redis://default:VugDBHGYAectnTj25wmCCAuhPOu3xkhk@redis-11344.c240.us-east-1-3.ec2.cloud.redislabs.com:11344',
|
|
||||||
// pingInterval: 60000
|
|
||||||
// });
|
|
||||||
|
|
||||||
// client2.on('error', err => console.error('22222', err, new Date().toJSON()));
|
|
||||||
|
|
||||||
// await client2.connect();
|
|
||||||
|
|
||||||
import { createClient, RESP_TYPES } from '@redis/client';
|
|
||||||
|
|
||||||
const client = createClient({
|
|
||||||
RESP: 3,
|
|
||||||
name: 'test',
|
|
||||||
commandOptions: {
|
|
||||||
asap: true,
|
|
||||||
typeMapping: {
|
|
||||||
[RESP_TYPES.BLOB_STRING]: Buffer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
client.on('error', err => console.error(err));
|
|
||||||
|
|
||||||
await client.connect();
|
|
||||||
|
|
||||||
|
|
||||||
const controller = new AbortController();
|
|
||||||
|
|
||||||
try {
|
|
||||||
const promise = client.withAbortSignal(controller.signal).set('key', 'value');
|
|
||||||
controller.abort();
|
|
||||||
console.log('!!', await promise);
|
|
||||||
} catch (err) {
|
|
||||||
// AbortError
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
client.ping('a'),
|
|
||||||
client.ping('b')
|
|
||||||
])
|
|
||||||
|
|
||||||
const asap = client.asap();
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
asap.ping('aa'),
|
|
||||||
asap.ping('bb')
|
|
||||||
])
|
|
||||||
|
|
||||||
await client.set('another', 'value');
|
|
||||||
|
|
||||||
for await (const keys of client.scanIterator()) {
|
|
||||||
console.log(keys);
|
|
||||||
}
|
|
||||||
|
|
||||||
// console.log(
|
|
||||||
// await Promise.all([
|
|
||||||
// client.get('key'),
|
|
||||||
// client.asap().get('a'),
|
|
||||||
// client.withTypeMapping({}).get('key')
|
|
||||||
// ])
|
|
||||||
// );
|
|
||||||
|
|
||||||
// await client.set('key', 'value');
|
|
||||||
|
|
||||||
// const controller = new AbortController();
|
|
||||||
|
|
||||||
// controller.abort();
|
|
||||||
|
|
||||||
// client.withAbortSignal(controller.signal).get('key')
|
|
||||||
// .then(a => console.log(a))
|
|
||||||
// .catch(err => {
|
|
||||||
// console.error(err);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// controller.abort();
|
|
||||||
|
|
||||||
// client.destroy();
|
|
@@ -5,8 +5,7 @@
|
|||||||
"path": "./packages/test-utils"
|
"path": "./packages/test-utils"
|
||||||
}, {
|
}, {
|
||||||
"path": "./packages/bloom"
|
"path": "./packages/bloom"
|
||||||
}],
|
}, {
|
||||||
"todo": [{
|
|
||||||
"path": "./packages/graph"
|
"path": "./packages/graph"
|
||||||
}, {
|
}, {
|
||||||
"path": "./packages/json"
|
"path": "./packages/json"
|
||||||
@@ -16,10 +15,5 @@
|
|||||||
"path": "./packages/time-series"
|
"path": "./packages/time-series"
|
||||||
}, {
|
}, {
|
||||||
"path": "./packages/redis"
|
"path": "./packages/redis"
|
||||||
}],
|
}]
|
||||||
"typedocOptions": {
|
|
||||||
"entryPoints": ["./packages/client"],
|
|
||||||
"entryPointStrategy": "packages",
|
|
||||||
"out": "./documentation"
|
|
||||||
}
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user