You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
more commands
This commit is contained in:
@@ -1,30 +1,30 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './ARRAPPEND';
|
||||
import ARRAPPEND from './ARRAPPEND';
|
||||
|
||||
describe('ARRAPPEND', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('single JSON', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$', 1),
|
||||
['JSON.ARRAPPEND', 'key', '$', '1']
|
||||
);
|
||||
});
|
||||
|
||||
it('multiple JSONs', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$', 1, 2),
|
||||
['JSON.ARRAPPEND', 'key', '$', '1', '2']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('single JSON', () => {
|
||||
assert.deepEqual(
|
||||
ARRAPPEND.transformArguments('key', '$', 1),
|
||||
['JSON.ARRAPPEND', 'key', '$', '1']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.json.arrAppend', async client => {
|
||||
await client.json.set('key', '$', []);
|
||||
it('multiple JSONs', () => {
|
||||
assert.deepEqual(
|
||||
ARRAPPEND.transformArguments('key', '$', 1, 2),
|
||||
['JSON.ARRAPPEND', 'key', '$', '1', '2']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
await client.json.arrAppend('key', '$', 1),
|
||||
[1]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
testUtils.testWithClient('client.json.arrAppend', async client => {
|
||||
await client.json.set('key', '$', []);
|
||||
|
||||
assert.deepEqual(
|
||||
await client.json.arrAppend('key', '$', 1),
|
||||
[1]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,15 +1,17 @@
|
||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||
import { RedisArgument, ArrayReply, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(key: string, path: string, ...jsons: Array<RedisJSON>): Array<string> {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path: RedisArgument, ...jsons: Array<RedisJSON>) {
|
||||
const args = ['JSON.ARRAPPEND', key, path];
|
||||
|
||||
for (const json of jsons) {
|
||||
args.push(transformRedisJsonArgument(json));
|
||||
args.push(transformRedisJsonArgument(json));
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): number | Array<number>;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,37 +1,37 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './ARRINDEX';
|
||||
import ARRINDEX from './ARRINDEX';
|
||||
|
||||
describe('ARRINDEX', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$', 'json'),
|
||||
['JSON.ARRINDEX', 'key', '$', '"json"']
|
||||
);
|
||||
});
|
||||
|
||||
it('with start', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$', 'json', 1),
|
||||
['JSON.ARRINDEX', 'key', '$', '"json"', '1']
|
||||
);
|
||||
});
|
||||
|
||||
it('with start, end', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$', 'json', 1, 2),
|
||||
['JSON.ARRINDEX', 'key', '$', '"json"', '1', '2']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
ARRINDEX.transformArguments('key', '$', 'json'),
|
||||
['JSON.ARRINDEX', 'key', '$', '"json"']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.json.arrIndex', async client => {
|
||||
await client.json.set('key', '$', []);
|
||||
it('with start', () => {
|
||||
assert.deepEqual(
|
||||
ARRINDEX.transformArguments('key', '$', 'json', 1),
|
||||
['JSON.ARRINDEX', 'key', '$', '"json"', '1']
|
||||
);
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
await client.json.arrIndex('key', '$', 'json'),
|
||||
[-1]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
it('with start, end', () => {
|
||||
assert.deepEqual(
|
||||
ARRINDEX.transformArguments('key', '$', 'json', 1, 2),
|
||||
['JSON.ARRINDEX', 'key', '$', '"json"', '1', '2']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.json.arrIndex', async client => {
|
||||
await client.json.set('key', '$', []);
|
||||
|
||||
assert.deepEqual(
|
||||
await client.json.arrIndex('key', '$', 'json'),
|
||||
[-1]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,21 +1,27 @@
|
||||
import { RedisArgument, ArrayReply, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(key: string, path: string, json: RedisJSON, start?: number, stop?: number): Array<string> {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(
|
||||
key: RedisArgument,
|
||||
path: RedisArgument,
|
||||
json: RedisJSON,
|
||||
start?: number,
|
||||
stop?: number
|
||||
) {
|
||||
const args = ['JSON.ARRINDEX', key, path, transformRedisJsonArgument(json)];
|
||||
|
||||
if (start !== undefined && start !== null) {
|
||||
args.push(start.toString());
|
||||
args.push(start.toString());
|
||||
|
||||
if (stop !== undefined && stop !== null) {
|
||||
args.push(stop.toString());
|
||||
}
|
||||
if (stop !== undefined && stop !== null) {
|
||||
args.push(stop.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): number | Array<number>;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply>
|
||||
} as const satisfies Command;
|
||||
|
Reference in New Issue
Block a user