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 = {
|
||||
// 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);
|
||||
|
@@ -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<number>` -> `Array<boolean>`
|
||||
- `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
|
||||
|
||||
|
@@ -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<TuplesReply<[NumberReply, BlobStringReply]>>) {
|
||||
return {
|
||||
iterator: reply[0],
|
||||
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<[
|
||||
[BlobStringReply<'width'>, NumberReply],
|
||||
@@ -13,7 +13,7 @@ export default {
|
||||
return ['CMS.INFO', key];
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: Resp2Reply<BfInfoReply>) => ({
|
||||
2: (reply: UnwrapReply<Resp2Reply<BfInfoReply>>) => ({
|
||||
width: reply[1],
|
||||
depth: reply[3],
|
||||
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 {
|
||||
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<TuplesReply<[NumberReply, BlobStringReply | NullReply]>>) {
|
||||
return {
|
||||
iterator: reply[0],
|
||||
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<[
|
||||
[BlobStringReply<'k'>, NumberReply],
|
||||
@@ -14,7 +14,7 @@ export default {
|
||||
return ['TOPK.INFO', key];
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: Resp2Reply<TopKInfoReply>) => ({
|
||||
2: (reply: UnwrapReply<Resp2Reply<TopKInfoReply>>) => ({
|
||||
k: reply[1],
|
||||
width: reply[3],
|
||||
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 {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
@@ -6,11 +6,11 @@ export default {
|
||||
transformArguments(key: RedisArgument) {
|
||||
return ['TOPK.LIST', key, 'WITHCOUNT'];
|
||||
},
|
||||
transformReply(rawReply: ArrayReply<SimpleStringReply | NumberReply>) {
|
||||
const reply = [] as unknown as ArrayReply<{
|
||||
transformReply(rawReply: UnwrapReply<ArrayReply<SimpleStringReply | NumberReply>>) {
|
||||
const reply: Array<{
|
||||
item: SimpleStringReply;
|
||||
count: NumberReply;
|
||||
}>;
|
||||
}> = [];
|
||||
|
||||
for (let i = 0; i < rawReply.length; i++) {
|
||||
reply.push({
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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<NumberReply | NullReply>
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -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(
|
||||
@@ -11,27 +11,39 @@ describe('ARRINDEX', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('with start', () => {
|
||||
|
||||
describe('with range', () => {
|
||||
it('start only', () => {
|
||||
assert.deepEqual(
|
||||
ARRINDEX.transformArguments('key', '$', 'json', 1),
|
||||
['JSON.ARRINDEX', 'key', '$', '"json"', '1']
|
||||
ARRINDEX.transformArguments('key', '$', 'json', {
|
||||
range: {
|
||||
start: 0
|
||||
}
|
||||
}),
|
||||
['JSON.ARRINDEX', 'key', '$', '"json"', '0']
|
||||
);
|
||||
});
|
||||
|
||||
it('with start, end', () => {
|
||||
it('with start and stop', () => {
|
||||
assert.deepEqual(
|
||||
ARRINDEX.transformArguments('key', '$', 'json', 1, 2),
|
||||
['JSON.ARRINDEX', 'key', '$', '"json"', '1', '2']
|
||||
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);
|
||||
});
|
||||
|
@@ -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<NumberReply | NullReply>
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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<RedisJSON>) {
|
||||
const args = ['JSON.ARRINSERT', key, path, index.toString()];
|
||||
transformArguments(
|
||||
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) {
|
||||
args.push(transformRedisJsonArgument(json));
|
||||
@@ -13,5 +25,5 @@ export default {
|
||||
|
||||
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;
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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<NumberReply | NullReply>
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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<NumberReply | NullReply>
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -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', '$']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -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;
|
||||
},
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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,
|
||||
|
@@ -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']
|
||||
);
|
||||
});
|
||||
|
@@ -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;
|
||||
|
@@ -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']
|
||||
);
|
||||
});
|
||||
|
@@ -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;
|
||||
|
@@ -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<string>;
|
||||
INDENT?: string;
|
||||
NEWLINE?: string;
|
||||
SPACE?: string;
|
||||
NOESCAPE?: true;
|
||||
}
|
||||
// interface GetOptions {
|
||||
// path?: string | Array<string>;
|
||||
// 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 '.';
|
||||
|
@@ -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<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;
|
||||
|
@@ -1,7 +1,5 @@
|
||||
import { RedisArgument, ArrayReply, BlobStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
|
||||
type ReplyItem = ArrayReply<BlobStringReply> | 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<ReplyItem>
|
||||
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply> | ArrayReply<ArrayReply<BlobStringReply> | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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<NumberReply | NullReply>
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -19,3 +19,14 @@
|
||||
// }
|
||||
|
||||
// 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 => {
|
||||
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);
|
||||
});
|
||||
|
@@ -12,5 +12,5 @@ export default {
|
||||
|
||||
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;
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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;
|
||||
},
|
||||
|
@@ -1,24 +1,25 @@
|
||||
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,
|
||||
@@ -31,8 +32,8 @@ export default {
|
||||
clear: CLEAR,
|
||||
ARRLEN,
|
||||
arrLen: ARRLEN,
|
||||
ARRPOP,
|
||||
arrPop: ARRPOP,
|
||||
// ARRPOP,
|
||||
// arrPop: ARRPOP,
|
||||
ARRTRIM,
|
||||
arrTrim: ARRTRIM,
|
||||
DEBUG_MEMORY,
|
||||
@@ -41,10 +42,10 @@ export default {
|
||||
del: DEL,
|
||||
FORGET,
|
||||
forget: FORGET,
|
||||
GET,
|
||||
get: GET,
|
||||
MGET,
|
||||
mGet: MGET,
|
||||
// GET,
|
||||
// get: GET,
|
||||
// MGET,
|
||||
// mGet: MGET,
|
||||
NUMINCRBY,
|
||||
numIncrBy: NUMINCRBY,
|
||||
NUMMULTBY,
|
||||
@@ -53,21 +54,23 @@ export default {
|
||||
objKeys: OBJKEYS,
|
||||
OBJLEN,
|
||||
objLen: OBJLEN,
|
||||
RESP,
|
||||
resp: RESP,
|
||||
// RESP,
|
||||
// resp: RESP,
|
||||
SET,
|
||||
set: SET,
|
||||
STRAPPEND,
|
||||
strAppend: STRAPPEND,
|
||||
STRLEN,
|
||||
strLen: STRLEN,
|
||||
TYPE,
|
||||
type: TYPE
|
||||
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<RedisJSON> {}
|
||||
interface RedisJSONArray extends Array<RedisJSON> { }
|
||||
interface RedisJSONObject {
|
||||
[key: string]: 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 {
|
||||
LATEST?: boolean;
|
||||
@@ -19,13 +19,13 @@ export default {
|
||||
return args;
|
||||
},
|
||||
transformReply: {
|
||||
2(reply: Resp2Reply<TsGetReply>) {
|
||||
2(reply: UnwrapReply<Resp2Reply<TsGetReply>>) {
|
||||
return reply.length === 0 ? null : {
|
||||
timestamp: reply[0],
|
||||
value: Number(reply[1])
|
||||
};
|
||||
},
|
||||
3(reply: TsGetReply) {
|
||||
3(reply: UnwrapReply<TsGetReply>) {
|
||||
return reply.length === 0 ? null : {
|
||||
timestamp: reply[0],
|
||||
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/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"
|
||||
}
|
||||
}]
|
||||
}
|
Reference in New Issue
Block a user