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

Update doctest client with latest v4 release (#2844)

This commit is contained in:
Shaya Potter
2024-09-29 13:19:06 +03:00
committed by GitHub
parent fd7b10be6c
commit 49fdb79897
167 changed files with 8227 additions and 9599 deletions

View File

@@ -0,0 +1,21 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './MERGE';
describe('MERGE', () => {
testUtils.isVersionGreaterThanHook([2, 6]);
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', '$', 1),
['JSON.MERGE', 'key', '$', '1']
);
});
testUtils.testWithClient('client.json.merge', async client => {
assert.equal(
await client.json.merge('key', '$', 'json'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,9 @@
import { RedisJSON, transformRedisJsonArgument } from '.';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string, path: string, json: RedisJSON): Array<string> {
return ['JSON.MERGE', key, path, transformRedisJsonArgument(json)];
}
export declare function transformReply(): 'OK';

View File

@@ -2,6 +2,8 @@ import { RedisJSON, transformRedisJsonNullReply } from '.';
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
export function transformArguments(keys: Array<string>, path: string): Array<string> {
return [
'JSON.MGET',

View File

@@ -0,0 +1,35 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './MSET';
describe('MSET', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments([{
key: '1',
path: '$',
value: 1
}, {
key: '2',
path: '$',
value: '2'
}]),
['JSON.MSET', '1', '$', '1', '2', '$', '"2"']
);
});
testUtils.testWithClient('client.json.mSet', async client => {
assert.deepEqual(
await client.json.mSet([{
key: '1',
path: '$',
value: 1
}, {
key: '2',
path: '$',
value: '2'
}]),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,28 @@
import { RedisJSON, transformRedisJsonArgument } from '.';
import { RedisCommandArgument } from '@redis/client/dist/lib/commands';
export const FIRST_KEY_INDEX = 1;
interface JsonMSetItem {
key: RedisCommandArgument;
path: RedisCommandArgument;
value: RedisJSON;
}
export function transformArguments(items: Array<JsonMSetItem>): Array<string> {
const args = new Array(1 + items.length * 3);
args[0] = 'JSON.MSET';
let argsIndex = 1;
for (let i = 0; i < items.length; i++) {
const item = items[i];
args[argsIndex++] = item.key;
args[argsIndex++] = item.path;
args[argsIndex++] = transformRedisJsonArgument(item.value);
}
return args;
}
export declare function transformReply(): 'OK';

View File

@@ -8,7 +8,9 @@ import * as DEBUG_MEMORY from './DEBUG_MEMORY';
import * as DEL from './DEL';
import * as FORGET from './FORGET';
import * as GET from './GET';
import * as MERGE from './MERGE';
import * as MGET from './MGET';
import * as MSET from './MSET';
import * as NUMINCRBY from './NUMINCRBY';
import * as NUMMULTBY from './NUMMULTBY';
import * as OBJKEYS from './OBJKEYS';
@@ -40,8 +42,12 @@ export default {
forget: FORGET,
GET,
get: GET,
MERGE,
merge: MERGE,
MGET,
mGet: MGET,
MSET,
mSet: MSET,
NUMINCRBY,
numIncrBy: NUMINCRBY,
NUMMULTBY,