diff --git a/benchmark/lib/ping/local-resp3-buffer-proxy.js b/benchmark/lib/ping/local-resp3-buffer-proxy.js new file mode 100644 index 0000000000..2ded38b21c --- /dev/null +++ b/benchmark/lib/ping/local-resp3-buffer-proxy.js @@ -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(); + } + }; +}; diff --git a/benchmark/lib/ping/local-resp3-buffer.js b/benchmark/lib/ping/local-resp3-buffer.js new file mode 100644 index 0000000000..624a524ce0 --- /dev/null +++ b/benchmark/lib/ping/local-resp3-buffer.js @@ -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(); + } + }; +}; diff --git a/benchmark/lib/runner.js b/benchmark/lib/runner.js index 3787cbabd1..fd61a1a1e5 100644 --- a/benchmark/lib/runner.js +++ b/benchmark/lib/runner.js @@ -73,11 +73,11 @@ const benchmarkStart = process.hrtime.bigint(), json = { // timestamp, operationsPerSecond: times / Number(benchmarkNanoseconds) * 1_000_000_000, - // p0: histogram.getValueAtPercentile(0), - // p50: histogram.getValueAtPercentile(50), - // p95: histogram.getValueAtPercentile(95), - // p99: histogram.getValueAtPercentile(99), - // p100: histogram.getValueAtPercentile(100) + p0: histogram.getValueAtPercentile(0), + p50: histogram.getValueAtPercentile(50), + p95: histogram.getValueAtPercentile(95), + p99: histogram.getValueAtPercentile(99), + p100: histogram.getValueAtPercentile(100) }; console.log(`[${basename(path)}]:`); console.table(json); diff --git a/docs/v4-to-v5.md b/docs/v4-to-v5.md index 9536523ae0..66d94fb0a8 100644 --- a/docs/v4-to-v5.md +++ b/docs/v4-to-v5.md @@ -177,6 +177,10 @@ Some command arguments/replies have changed to align more closely to data types - `FT.SUGDEL`: [^boolean-to-number] - `TOPK.QUERY`: `Array` -> `Array` - `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 diff --git a/packages/bloom/lib/commands/bloom/SCANDUMP.ts b/packages/bloom/lib/commands/bloom/SCANDUMP.ts index be5367b872..588957b174 100644 --- a/packages/bloom/lib/commands/bloom/SCANDUMP.ts +++ b/packages/bloom/lib/commands/bloom/SCANDUMP.ts @@ -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 { FIRST_KEY_INDEX: 1, @@ -6,7 +6,7 @@ export default { transformArguments(key: RedisArgument, iterator: number) { return ['BF.SCANDUMP', key, iterator.toString()]; }, - transformReply(reply: TuplesReply<[NumberReply, BlobStringReply]>) { + transformReply(reply: UnwrapReply>) { return { iterator: reply[0], chunk: reply[1] diff --git a/packages/bloom/lib/commands/count-min-sketch/INFO.ts b/packages/bloom/lib/commands/count-min-sketch/INFO.ts index e298efd16a..8ded9b6cd6 100644 --- a/packages/bloom/lib/commands/count-min-sketch/INFO.ts +++ b/packages/bloom/lib/commands/count-min-sketch/INFO.ts @@ -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<[ [BlobStringReply<'width'>, NumberReply], @@ -13,7 +13,7 @@ export default { return ['CMS.INFO', key]; }, transformReply: { - 2: (reply: Resp2Reply) => ({ + 2: (reply: UnwrapReply>) => ({ width: reply[1], depth: reply[3], count: reply[5] diff --git a/packages/bloom/lib/commands/cuckoo/SCANDUMP.ts b/packages/bloom/lib/commands/cuckoo/SCANDUMP.ts index af33315750..dc07668928 100644 --- a/packages/bloom/lib/commands/cuckoo/SCANDUMP.ts +++ b/packages/bloom/lib/commands/cuckoo/SCANDUMP.ts @@ -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 { FIRST_KEY_INDEX: 1, @@ -6,7 +6,7 @@ export default { transformArguments(key: RedisArgument, iterator: number) { return ['CF.SCANDUMP', key, iterator.toString()]; }, - transformReply(reply: TuplesReply<[NumberReply, BlobStringReply | NullReply]>) { + transformReply(reply: UnwrapReply>) { return { iterator: reply[0], chunk: reply[1] diff --git a/packages/bloom/lib/commands/top-k/INFO.ts b/packages/bloom/lib/commands/top-k/INFO.ts index bd694eace2..6d943b7a02 100644 --- a/packages/bloom/lib/commands/top-k/INFO.ts +++ b/packages/bloom/lib/commands/top-k/INFO.ts @@ -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<[ [BlobStringReply<'k'>, NumberReply], @@ -14,7 +14,7 @@ export default { return ['TOPK.INFO', key]; }, transformReply: { - 2: (reply: Resp2Reply) => ({ + 2: (reply: UnwrapReply>) => ({ k: reply[1], width: reply[3], depth: reply[5], diff --git a/packages/bloom/lib/commands/top-k/LIST_WITHCOUNT.ts b/packages/bloom/lib/commands/top-k/LIST_WITHCOUNT.ts index a135e5db46..a4a5249c5b 100644 --- a/packages/bloom/lib/commands/top-k/LIST_WITHCOUNT.ts +++ b/packages/bloom/lib/commands/top-k/LIST_WITHCOUNT.ts @@ -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 { FIRST_KEY_INDEX: 1, @@ -6,11 +6,11 @@ export default { transformArguments(key: RedisArgument) { return ['TOPK.LIST', key, 'WITHCOUNT']; }, - transformReply(rawReply: ArrayReply) { - const reply = [] as unknown as ArrayReply<{ + transformReply(rawReply: UnwrapReply>) { + const reply: Array<{ item: SimpleStringReply; count: NumberReply; - }>; + }> = []; for (let i = 0; i < rawReply.length; i++) { reply.push({ diff --git a/packages/json/lib/commands/ARRAPPEND.spec.ts b/packages/json/lib/commands/ARRAPPEND.spec.ts index cd2001d5ea..991185dd92 100644 --- a/packages/json/lib/commands/ARRAPPEND.spec.ts +++ b/packages/json/lib/commands/ARRAPPEND.spec.ts @@ -20,11 +20,11 @@ describe('ARRAPPEND', () => { }); 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( - await client.json.arrAppend('key', '$', 1), - [1] - ); + assert.deepEqual(reply, [1]); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/json/lib/commands/ARRAPPEND.ts b/packages/json/lib/commands/ARRAPPEND.ts index 934a534cfc..7f5b49eead 100644 --- a/packages/json/lib/commands/ARRAPPEND.ts +++ b/packages/json/lib/commands/ARRAPPEND.ts @@ -1,5 +1,5 @@ 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 { FIRST_KEY_INDEX: 1, @@ -13,5 +13,5 @@ export default { return args; }, - transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply + transformReply: undefined as unknown as () => NumberReply | ArrayReply } as const satisfies Command; diff --git a/packages/json/lib/commands/ARRINDEX.spec.ts b/packages/json/lib/commands/ARRINDEX.spec.ts index 290d0a237f..fc65dbdf0f 100644 --- a/packages/json/lib/commands/ARRINDEX.spec.ts +++ b/packages/json/lib/commands/ARRINDEX.spec.ts @@ -2,7 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import ARRINDEX from './ARRINDEX'; -describe('ARRINDEX', () => { +describe('JSON.ARRINDEX', () => { describe('transformArguments', () => { it('simple', () => { assert.deepEqual( @@ -10,28 +10,40 @@ describe('ARRINDEX', () => { ['JSON.ARRINDEX', 'key', '$', '"json"'] ); }); + - it('with start', () => { - assert.deepEqual( - ARRINDEX.transformArguments('key', '$', 'json', 1), - ['JSON.ARRINDEX', 'key', '$', '"json"', '1'] - ); - }); + describe('with range', () => { + it('start only', () => { + assert.deepEqual( + ARRINDEX.transformArguments('key', '$', 'json', { + range: { + start: 0 + } + }), + ['JSON.ARRINDEX', 'key', '$', '"json"', '0'] + ); + }); - it('with start, end', () => { - assert.deepEqual( - ARRINDEX.transformArguments('key', '$', 'json', 1, 2), - ['JSON.ARRINDEX', 'key', '$', '"json"', '1', '2'] - ); + it('with start and stop', () => { + assert.deepEqual( + ARRINDEX.transformArguments('key', '$', 'json', { + range: { + start: 0, + stop: 1 + } + }), + ['JSON.ARRINDEX', 'key', '$', '"json"', '0', '1'] + ); + }); }); }); 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( - await client.json.arrIndex('key', '$', 'json'), - [-1] - ); + assert.deepEqual(reply, [-1]); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/json/lib/commands/ARRINDEX.ts b/packages/json/lib/commands/ARRINDEX.ts index f085e1afb9..77c54b9252 100644 --- a/packages/json/lib/commands/ARRINDEX.ts +++ b/packages/json/lib/commands/ARRINDEX.ts @@ -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 '.'; +export interface JsonArrIndexOptions { + range?: { + start: number; + stop?: number; + }; +} + export default { FIRST_KEY_INDEX: 1, IS_READ_ONLY: true, @@ -8,20 +15,19 @@ export default { key: RedisArgument, path: RedisArgument, json: RedisJSON, - start?: number, - stop?: number + options?: JsonArrIndexOptions ) { const args = ['JSON.ARRINDEX', key, path, transformRedisJsonArgument(json)]; - if (start !== undefined && start !== null) { - args.push(start.toString()); + if (options?.range) { + args.push(options.range.start.toString()); - if (stop !== undefined && stop !== null) { - args.push(stop.toString()); + if (options.range.stop !== undefined) { + args.push(options.range.stop.toString()); } } return args; }, - transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply + transformReply: undefined as unknown as () => NumberReply | ArrayReply } as const satisfies Command; diff --git a/packages/json/lib/commands/ARRINSERT.spec.ts b/packages/json/lib/commands/ARRINSERT.spec.ts index 8bf3d0d633..e081593539 100644 --- a/packages/json/lib/commands/ARRINSERT.spec.ts +++ b/packages/json/lib/commands/ARRINSERT.spec.ts @@ -20,11 +20,11 @@ describe('JSON.ARRINSERT', () => { }); 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( - await client.json.arrInsert('key', '$', 0, 'json'), - [1] - ); + assert.deepEqual(reply, [1]); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/json/lib/commands/ARRINSERT.ts b/packages/json/lib/commands/ARRINSERT.ts index 66663c646f..da2a3ed440 100644 --- a/packages/json/lib/commands/ARRINSERT.ts +++ b/packages/json/lib/commands/ARRINSERT.ts @@ -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 '.'; export default { FIRST_KEY_INDEX: 1, IS_READ_ONLY: false, - transformArguments(key: RedisArgument, path: RedisArgument, index: number, ...jsons: Array) { - const args = ['JSON.ARRINSERT', key, path, index.toString()]; + transformArguments( + key: RedisArgument, + path: RedisArgument, + index: number, + json: RedisJSON, + ...jsons: Array + ) { + const args = [ + 'JSON.ARRINSERT', + key, + path, + index.toString(), + transformRedisJsonArgument(json) + ]; for (const json of jsons) { args.push(transformRedisJsonArgument(json)); @@ -13,5 +25,5 @@ export default { return args; }, - transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply + transformReply: undefined as unknown as () => NumberReply | ArrayReply } as const satisfies Command; diff --git a/packages/json/lib/commands/ARRLEN.spec.ts b/packages/json/lib/commands/ARRLEN.spec.ts index 803b108dde..ec2e0e46f5 100644 --- a/packages/json/lib/commands/ARRLEN.spec.ts +++ b/packages/json/lib/commands/ARRLEN.spec.ts @@ -4,7 +4,7 @@ import ARRLEN from './ARRLEN'; describe('JSON.ARRLEN', () => { describe('transformArguments', () => { - it('without path', () => { + it('simple', () => { assert.deepEqual( ARRLEN.transformArguments('key'), ['JSON.ARRLEN', 'key'] @@ -13,18 +13,20 @@ describe('JSON.ARRLEN', () => { it('with path', () => { assert.deepEqual( - ARRLEN.transformArguments('key', '$'), + ARRLEN.transformArguments('key', { + path: '$' + }), ['JSON.ARRLEN', 'key', '$'] ); }); }); 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( - await client.json.arrLen('key', '$'), - [0] - ); + assert.deepEqual(reply, 0); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/json/lib/commands/ARRLEN.ts b/packages/json/lib/commands/ARRLEN.ts index 26155a109d..5763b893fa 100644 --- a/packages/json/lib/commands/ARRLEN.ts +++ b/packages/json/lib/commands/ARRLEN.ts @@ -1,16 +1,20 @@ import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types'; +export interface JsonArrLenOptions { + path?: RedisArgument; +} + export default { FIRST_KEY_INDEX: 1, IS_READ_ONLY: true, - transformArguments(key: RedisArgument, path?: RedisArgument) { + transformArguments(key: RedisArgument, options?: JsonArrLenOptions) { const args = ['JSON.ARRLEN', key]; - if (path) { - args.push(path); + if (options?.path) { + args.push(options.path); } return args; }, - transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply + transformReply: undefined as unknown as () => NumberReply | ArrayReply } as const satisfies Command; diff --git a/packages/json/lib/commands/ARRTRIM.spec.ts b/packages/json/lib/commands/ARRTRIM.spec.ts index 241c1b509b..03cd80a0e7 100644 --- a/packages/json/lib/commands/ARRTRIM.spec.ts +++ b/packages/json/lib/commands/ARRTRIM.spec.ts @@ -11,11 +11,11 @@ describe('JSON.ARRTRIM', () => { }); 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( - await client.json.arrTrim('key', '$', 0, 1), - [0] - ); + assert.deepEqual(reply, [0]); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/json/lib/commands/ARRTRIM.ts b/packages/json/lib/commands/ARRTRIM.ts index a3de83fff1..ab31f15949 100644 --- a/packages/json/lib/commands/ARRTRIM.ts +++ b/packages/json/lib/commands/ARRTRIM.ts @@ -6,5 +6,5 @@ export default { transformArguments(key: RedisArgument, path: RedisArgument, start: number, stop: number) { return ['JSON.ARRTRIM', key, path, start.toString(), stop.toString()]; }, - transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply + transformReply: undefined as unknown as () => NumberReply | ArrayReply } as const satisfies Command; diff --git a/packages/json/lib/commands/CLEAR.spec.ts b/packages/json/lib/commands/CLEAR.spec.ts index 5b53b77c3c..e9ada575a8 100644 --- a/packages/json/lib/commands/CLEAR.spec.ts +++ b/packages/json/lib/commands/CLEAR.spec.ts @@ -4,17 +4,19 @@ import CLEAR from './CLEAR'; describe('JSON.CLEAR', () => { describe('transformArguments', () => { - it('key', () => { + it('simple', () => { assert.deepEqual( CLEAR.transformArguments('key'), ['JSON.CLEAR', 'key'] ); }); - it('key, path', () => { + it('with path', () => { assert.deepEqual( - CLEAR.transformArguments('key', '$.path'), - ['JSON.CLEAR', 'key', '$.path'] + CLEAR.transformArguments('key', { + path: '$' + }), + ['JSON.CLEAR', 'key', '$'] ); }); }); diff --git a/packages/json/lib/commands/CLEAR.ts b/packages/json/lib/commands/CLEAR.ts index a5730f5b4e..186ce296bc 100644 --- a/packages/json/lib/commands/CLEAR.ts +++ b/packages/json/lib/commands/CLEAR.ts @@ -1,12 +1,18 @@ import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types'; +export interface JsonClearOptions { + path?: RedisArgument; +} + export default { FIRST_KEY_INDEX: 1, IS_READ_ONLY: false, - transformArguments(key: RedisArgument, path?: RedisArgument) { + transformArguments(key: RedisArgument, options?: JsonClearOptions) { const args = ['JSON.CLEAR', key]; - if (path) args.push(path); + if (options?.path) { + args.push(options.path); + } return args; }, diff --git a/packages/json/lib/commands/DEBUG_MEMORY.spec.ts b/packages/json/lib/commands/DEBUG_MEMORY.spec.ts index 51b6f7e2da..b0e969ab17 100644 --- a/packages/json/lib/commands/DEBUG_MEMORY.spec.ts +++ b/packages/json/lib/commands/DEBUG_MEMORY.spec.ts @@ -2,7 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import DEBUG_MEMORY from './DEBUG_MEMORY'; -describe('DEBUG MEMORY', () => { +describe('JSON.DEBUG MEMORY', () => { describe('transformArguments', () => { it('without path', () => { 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( await client.json.debugMemory('key', '$'), - [] + 0 ); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/json/lib/commands/DEBUG_MEMORY.ts b/packages/json/lib/commands/DEBUG_MEMORY.ts index 3b1c446037..765d2da357 100644 --- a/packages/json/lib/commands/DEBUG_MEMORY.ts +++ b/packages/json/lib/commands/DEBUG_MEMORY.ts @@ -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 { FIRST_KEY_INDEX: 2, diff --git a/packages/json/lib/commands/DEL.spec.ts b/packages/json/lib/commands/DEL.spec.ts index 4d67d7cb3e..590f70d788 100644 --- a/packages/json/lib/commands/DEL.spec.ts +++ b/packages/json/lib/commands/DEL.spec.ts @@ -2,18 +2,20 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import DEL from './DEL'; -describe('DEL', () => { +describe('JSON.DEL', () => { describe('transformArguments', () => { - it('key', () => { + it('simple', () => { assert.deepEqual( DEL.transformArguments('key'), ['JSON.DEL', 'key'] ); }); - it('key, path', () => { + it('with path', () => { assert.deepEqual( - DEL.transformArguments('key', '$.path'), + DEL.transformArguments('key', { + path: '$.path' + }), ['JSON.DEL', 'key', '$.path'] ); }); diff --git a/packages/json/lib/commands/DEL.ts b/packages/json/lib/commands/DEL.ts index 922fc7a783..13632840c6 100644 --- a/packages/json/lib/commands/DEL.ts +++ b/packages/json/lib/commands/DEL.ts @@ -1,13 +1,17 @@ import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types'; +export interface JsonDelOptions { + path?: RedisArgument +} + export default { FIRST_KEY_INDEX: 1, IS_READ_ONLY: false, - transformArguments(key: RedisArgument, path?: RedisArgument) { + transformArguments(key: RedisArgument, options?: JsonDelOptions) { const args = ['JSON.DEL', key]; - if (path) { - args.push(path); + if (options?.path) { + args.push(options.path); } return args; diff --git a/packages/json/lib/commands/FORGET.spec.ts b/packages/json/lib/commands/FORGET.spec.ts index b0e1961506..ec9f2221eb 100644 --- a/packages/json/lib/commands/FORGET.spec.ts +++ b/packages/json/lib/commands/FORGET.spec.ts @@ -2,7 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import FORGET from './FORGET'; -describe('FORGET', () => { +describe('JSON.FORGET', () => { describe('transformArguments', () => { it('key', () => { assert.deepEqual( @@ -13,7 +13,9 @@ describe('FORGET', () => { it('key, path', () => { assert.deepEqual( - FORGET.transformArguments('key', '$.path'), + FORGET.transformArguments('key', { + path: '$.path' + }), ['JSON.FORGET', 'key', '$.path'] ); }); diff --git a/packages/json/lib/commands/FORGET.ts b/packages/json/lib/commands/FORGET.ts index b55015e948..1820f8f202 100644 --- a/packages/json/lib/commands/FORGET.ts +++ b/packages/json/lib/commands/FORGET.ts @@ -1,13 +1,17 @@ import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types'; +export interface JsonForgetOptions { + path?: RedisArgument; +} + export default { FIRST_KEY_INDEX: 1, IS_READ_ONLY: false, - transformArguments(key: RedisArgument, path?: RedisArgument) { + transformArguments(key: RedisArgument, options?: JsonForgetOptions) { const args = ['JSON.FORGET', key]; - if (path) { - args.push(path); + if (options?.path) { + args.push(options.path); } return args; diff --git a/packages/json/lib/commands/GET.ts b/packages/json/lib/commands/GET.ts index 107f9dd975..445f0b3eae 100644 --- a/packages/json/lib/commands/GET.ts +++ b/packages/json/lib/commands/GET.ts @@ -1,42 +1,42 @@ -import { pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers'; -import { RedisCommandArguments } from '@redis/client/dist/lib/commands'; +// import { pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers'; +// 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 { - path?: string | Array; - INDENT?: string; - NEWLINE?: string; - SPACE?: string; - NOESCAPE?: true; -} +// interface GetOptions { +// path?: string | Array; +// INDENT?: string; +// NEWLINE?: string; +// SPACE?: string; +// NOESCAPE?: true; +// } -export function transformArguments(key: string, options?: GetOptions): RedisCommandArguments { - let args: RedisCommandArguments = ['JSON.GET', key]; +// export function transformArguments(key: string, options?: GetOptions): RedisCommandArguments { +// let args: RedisCommandArguments = ['JSON.GET', key]; - if (options?.path) { - args = pushVariadicArguments(args, options.path); - } +// if (options?.path) { +// args = pushVariadicArguments(args, options.path); +// } - if (options?.INDENT) { - args.push('INDENT', options.INDENT); - } +// if (options?.INDENT) { +// args.push('INDENT', options.INDENT); +// } - if (options?.NEWLINE) { - args.push('NEWLINE', options.NEWLINE); - } +// if (options?.NEWLINE) { +// args.push('NEWLINE', options.NEWLINE); +// } - if (options?.SPACE) { - args.push('SPACE', options.SPACE); - } +// if (options?.SPACE) { +// args.push('SPACE', options.SPACE); +// } - if (options?.NOESCAPE) { - args.push('NOESCAPE'); - } +// if (options?.NOESCAPE) { +// args.push('NOESCAPE'); +// } - return args; -} +// return args; +// } -export { transformRedisJsonNullReply as transformReply } from '.'; +// export { transformRedisJsonNullReply as transformReply } from '.'; diff --git a/packages/json/lib/commands/NUMINCRBY.ts b/packages/json/lib/commands/NUMINCRBY.ts index d025c249dd..68c1de2b0b 100644 --- a/packages/json/lib/commands/NUMINCRBY.ts +++ b/packages/json/lib/commands/NUMINCRBY.ts @@ -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 { FIRST_KEY_INDEX: 1, @@ -6,5 +6,10 @@ export default { transformArguments(key: RedisArgument, path: RedisArgument, by: number) { return ['JSON.NUMINCRBY', key, path, by.toString()]; }, - transformReply: undefined as unknown as () => ArrayReply + transformReply: { + 2: (reply: UnwrapReply) => { + return JSON.parse(reply.toString()) as number | Array; + }, + 3: undefined as unknown as () => NumberReply | DoubleReply | NullReply + } } as const satisfies Command; diff --git a/packages/json/lib/commands/OBJKEYS.ts b/packages/json/lib/commands/OBJKEYS.ts index e9541bdb52..7b4d9d963d 100644 --- a/packages/json/lib/commands/OBJKEYS.ts +++ b/packages/json/lib/commands/OBJKEYS.ts @@ -1,7 +1,5 @@ import { RedisArgument, ArrayReply, BlobStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types'; -type ReplyItem = ArrayReply | NullReply; - export default { FIRST_KEY_INDEX: 1, IS_READ_ONLY: false, @@ -14,5 +12,5 @@ export default { return args; }, - transformReply: undefined as unknown as () => ReplyItem | ArrayReply + transformReply: undefined as unknown as () => ArrayReply | ArrayReply | NullReply> } as const satisfies Command; diff --git a/packages/json/lib/commands/OBJLEN.spec.ts b/packages/json/lib/commands/OBJLEN.spec.ts index b2eed67c52..edea703aa1 100644 --- a/packages/json/lib/commands/OBJLEN.spec.ts +++ b/packages/json/lib/commands/OBJLEN.spec.ts @@ -19,10 +19,10 @@ describe('JSON.OBJLEN', () => { }); }); - // testUtils.testWithClient('client.json.objLen', async client => { - // assert.equal( - // await client.json.objLen('key', '$'), - // [null] - // ); - // }, GLOBAL.SERVERS.OPEN); + testUtils.testWithClient('client.json.objLen', async client => { + assert.equal( + await client.json.objLen('key', '$'), + [null] + ); + }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/json/lib/commands/OBJLEN.ts b/packages/json/lib/commands/OBJLEN.ts index 4063feea39..45b8855561 100644 --- a/packages/json/lib/commands/OBJLEN.ts +++ b/packages/json/lib/commands/OBJLEN.ts @@ -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 { FIRST_KEY_INDEX: 1, - IS_READ_ONLY: false, + IS_READ_ONLY: true, transformArguments(key: RedisArgument, path?: RedisArgument) { const args = ['JSON.OBJLEN', key]; @@ -12,5 +12,5 @@ export default { return args; }, - transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply + transformReply: undefined as unknown as () => NumberReply | ArrayReply } as const satisfies Command; diff --git a/packages/json/lib/commands/STRAPPEND.ts b/packages/json/lib/commands/STRAPPEND.ts index 9f3ef316fd..3f8e98e6bc 100644 --- a/packages/json/lib/commands/STRAPPEND.ts +++ b/packages/json/lib/commands/STRAPPEND.ts @@ -19,3 +19,14 @@ // } // export declare function transformReply(): number | Array; + +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; diff --git a/packages/json/lib/commands/STRLEN.spec.ts b/packages/json/lib/commands/STRLEN.spec.ts index f05a45cf95..687a55553e 100644 --- a/packages/json/lib/commands/STRLEN.spec.ts +++ b/packages/json/lib/commands/STRLEN.spec.ts @@ -20,11 +20,11 @@ describe('JSON.STRLEN', () => { }); 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( - await client.json.strLen('key', '$'), - [0] - ); + assert.deepEqual(reply, [0]); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/json/lib/commands/STRLEN.ts b/packages/json/lib/commands/STRLEN.ts index a2bab3b1f4..256414fb91 100644 --- a/packages/json/lib/commands/STRLEN.ts +++ b/packages/json/lib/commands/STRLEN.ts @@ -12,5 +12,5 @@ export default { return args; }, - transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply + transformReply: undefined as unknown as () => NumberReply | ArrayReply } as const satisfies Command; diff --git a/packages/json/lib/commands/TOGGLE.spec.ts b/packages/json/lib/commands/TOGGLE.spec.ts index 7ffb509489..3ce922a7b8 100644 --- a/packages/json/lib/commands/TOGGLE.spec.ts +++ b/packages/json/lib/commands/TOGGLE.spec.ts @@ -20,11 +20,11 @@ describe('JSON.TOGGLE', () => { }); 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( - await client.json.toggle('key', '$'), - [0] - ); + assert.deepEqual(reply, [0]); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/json/lib/commands/TOGGLE.ts b/packages/json/lib/commands/TOGGLE.ts index 45b632952a..85e5e479aa 100644 --- a/packages/json/lib/commands/TOGGLE.ts +++ b/packages/json/lib/commands/TOGGLE.ts @@ -1,12 +1,14 @@ import { RedisArgument, ArrayReply, NumberReply, NullReply, Command, } from '@redis/client/dist/lib/RESP/types'; export default { - FIRST_KEY_INDEX: undefined, + FIRST_KEY_INDEX: 1, IS_READ_ONLY: false, transformArguments(key: RedisArgument, path?: RedisArgument) { const args = ['JSON.TOGGLE', key] - if (path) args.push(path); + if (path) { + args.push(path); + } return args; }, diff --git a/packages/json/lib/commands/index.ts b/packages/json/lib/commands/index.ts index 218462f4db..4405f1b423 100644 --- a/packages/json/lib/commands/index.ts +++ b/packages/json/lib/commands/index.ts @@ -1,93 +1,96 @@ -import * as ARRAPPEND from './ARRAPPEND'; -import * as ARRINDEX from './ARRINDEX'; -import * as ARRINSERT from './ARRINSERT'; +import ARRAPPEND from './ARRAPPEND'; +import ARRINDEX from './ARRINDEX'; +import ARRINSERT from './ARRINSERT'; import CLEAR from './CLEAR'; -import * as ARRLEN from './ARRLEN'; -import * as ARRPOP from './ARRPOP'; -import * as ARRTRIM from './ARRTRIM'; -import * as DEBUG_MEMORY from './DEBUG_MEMORY'; -import * as DEL from './DEL'; -import * as FORGET from './FORGET'; -import * as GET from './GET'; -import * as MGET from './MGET'; -import * as NUMINCRBY from './NUMINCRBY'; -import * as NUMMULTBY from './NUMMULTBY'; -import * as OBJKEYS from './OBJKEYS'; -import * as OBJLEN from './OBJLEN'; -import * as RESP from './RESP'; -import * as SET from './SET'; -import * as STRAPPEND from './STRAPPEND'; -import * as STRLEN from './STRLEN'; -import * as TYPE from './TYPE'; +import ARRLEN from './ARRLEN'; +// import ARRPOP from './ARRPOP'; +import ARRTRIM from './ARRTRIM'; +import DEBUG_MEMORY from './DEBUG_MEMORY'; +import DEL from './DEL'; +import FORGET from './FORGET'; +// import GET from './GET'; +// import MGET from './MGET'; +import NUMINCRBY from './NUMINCRBY'; +import NUMMULTBY from './NUMMULTBY'; +import OBJKEYS from './OBJKEYS'; +import OBJLEN from './OBJLEN'; +// import RESP from './RESP'; +import SET from './SET'; +import STRAPPEND from './STRAPPEND'; +import STRLEN from './STRLEN'; +import TOGGLE from './TOGGLE'; +// import TYPE from './TYPE'; export default { - ARRAPPEND, - arrAppend: ARRAPPEND, - ARRINDEX, - arrIndex: ARRINDEX, - ARRINSERT, - arrInsert: ARRINSERT, - CLEAR, - clear: CLEAR, - ARRLEN, - arrLen: ARRLEN, - ARRPOP, - arrPop: ARRPOP, - ARRTRIM, - arrTrim: ARRTRIM, - DEBUG_MEMORY, - debugMemory: DEBUG_MEMORY, - DEL, - del: DEL, - FORGET, - forget: FORGET, - GET, - get: GET, - MGET, - mGet: MGET, - NUMINCRBY, - numIncrBy: NUMINCRBY, - NUMMULTBY, - numMultBy: NUMMULTBY, - OBJKEYS, - objKeys: OBJKEYS, - OBJLEN, - objLen: OBJLEN, - RESP, - resp: RESP, - SET, - set: SET, - STRAPPEND, - strAppend: STRAPPEND, - STRLEN, - strLen: STRLEN, - TYPE, - type: TYPE + ARRAPPEND, + arrAppend: ARRAPPEND, + ARRINDEX, + arrIndex: ARRINDEX, + ARRINSERT, + arrInsert: ARRINSERT, + CLEAR, + clear: CLEAR, + ARRLEN, + arrLen: ARRLEN, + // ARRPOP, + // arrPop: ARRPOP, + ARRTRIM, + arrTrim: ARRTRIM, + DEBUG_MEMORY, + debugMemory: DEBUG_MEMORY, + DEL, + del: DEL, + FORGET, + forget: FORGET, + // GET, + // get: GET, + // MGET, + // mGet: MGET, + NUMINCRBY, + numIncrBy: NUMINCRBY, + NUMMULTBY, + numMultBy: NUMMULTBY, + OBJKEYS, + objKeys: OBJKEYS, + OBJLEN, + objLen: OBJLEN, + // RESP, + // resp: RESP, + SET, + set: SET, + STRAPPEND, + strAppend: STRAPPEND, + STRLEN, + strLen: STRLEN, + TOGGLE, + toggle: TOGGLE, + // TYPE, + // type: TYPE }; // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540 // eslint-disable-next-line @typescript-eslint/no-empty-interface -interface RedisJSONArray extends Array {} +interface RedisJSONArray extends Array { } interface RedisJSONObject { - [key: string]: RedisJSON; - [key: number]: RedisJSON; + [key: string]: RedisJSON; + [key: number]: RedisJSON; } export type RedisJSON = null | boolean | number | string | Date | RedisJSONArray | RedisJSONObject; export function transformRedisJsonArgument(json: RedisJSON): string { - return JSON.stringify(json); + return JSON.stringify(json); } export function transformRedisJsonReply(json: string): RedisJSON { - return JSON.parse(json); + return JSON.parse(json); } export function transformRedisJsonNullReply(json: string | null): RedisJSON | null { - if (json === null) return null; + if (json === null) return null; - return transformRedisJsonReply(json); + return transformRedisJsonReply(json); } export function transformNumbersReply(reply: string): number | Array { - return JSON.parse(reply); + return JSON.parse(reply); } diff --git a/packages/json/lib/test-utils.ts b/packages/json/lib/test-utils.ts index f4c4e4eb20..8c598e9090 100644 --- a/packages/json/lib/test-utils.ts +++ b/packages/json/lib/test-utils.ts @@ -2,19 +2,19 @@ import TestUtils from '@redis/test-utils'; import RedisJSON from '.'; export default new TestUtils({ - dockerImageName: 'redislabs/rejson', - dockerImageVersionArgument: 'rejson-version' + dockerImageName: 'redislabs/rejson', + dockerImageVersionArgument: 'rejson-version' }); export const GLOBAL = { - SERVERS: { - OPEN: { - serverArguments: ['--loadmodule /usr/lib/redis/modules/rejson.so'], - clientOptions: { - modules: { - json: RedisJSON - } - } + SERVERS: { + OPEN: { + serverArguments: ['--loadmodule /usr/lib/redis/modules/rejson.so'], + clientOptions: { + modules: { + json: RedisJSON } + } } + } }; diff --git a/packages/json/test.js b/packages/json/test.js new file mode 100644 index 0000000000..f9845cc430 --- /dev/null +++ b/packages/json/test.js @@ -0,0 +1,11 @@ +import { createClient } from '@redis/client'; +import RedisJSON from '.'; + +const client = createClient({ + modules: { + json: RedisJSON, + JSON: RedisJSON + } +}); + +client.JSON. \ No newline at end of file diff --git a/packages/time-series/lib/commands/GET.ts b/packages/time-series/lib/commands/GET.ts index 514b51edd2..78e5e3bced 100644 --- a/packages/time-series/lib/commands/GET.ts +++ b/packages/time-series/lib/commands/GET.ts @@ -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 { LATEST?: boolean; @@ -19,13 +19,13 @@ export default { return args; }, transformReply: { - 2(reply: Resp2Reply) { + 2(reply: UnwrapReply>) { return reply.length === 0 ? null : { timestamp: reply[0], value: Number(reply[1]) }; }, - 3(reply: TsGetReply) { + 3(reply: UnwrapReply) { return reply.length === 0 ? null : { timestamp: reply[0], value: reply[1] diff --git a/test.mjs b/test.mjs deleted file mode 100644 index 6aa12b67e5..0000000000 --- a/test.mjs +++ /dev/null @@ -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(); diff --git a/tsconfig.json b/tsconfig.json index 3c2207d4ff..c65451d427 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,8 +5,7 @@ "path": "./packages/test-utils" }, { "path": "./packages/bloom" - }], - "todo": [{ + }, { "path": "./packages/graph" }, { "path": "./packages/json" @@ -16,10 +15,5 @@ "path": "./packages/time-series" }, { "path": "./packages/redis" - }], - "typedocOptions": { - "entryPoints": ["./packages/client"], - "entryPointStrategy": "packages", - "out": "./documentation" - } + }] } \ No newline at end of file