You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
Support JSON.MERGE Command
This commit is contained in:
24
packages/json/lib/commands/MSET.spec.ts
Normal file
24
packages/json/lib/commands/MSET.spec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './MSET';
|
||||
|
||||
describe('MSET', () => {
|
||||
testUtils.isVersionGreaterThanHook([2, 6]);
|
||||
|
||||
describe('transformArguments', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments([{ key: "key", path: "$", value: "json" }, { key: "key2", path: "$", value: "json2" }]),
|
||||
['JSON.MSET', 'key', '$', '"json"', 'key2', '$', '"json2"']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
testUtils.testWithClient('client.json.mSet', async client => {
|
||||
assert.equal(
|
||||
await client.json.mSet([{ key: "key", path: "$", value: "json" }, { key: "key2", path: "$", value: "json2" }]),
|
||||
'OK'
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
24
packages/json/lib/commands/MSET.ts
Normal file
24
packages/json/lib/commands/MSET.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export interface KeyPathValue {
|
||||
key: string;
|
||||
path: string;
|
||||
value: RedisJSON;
|
||||
}
|
||||
|
||||
export function transformArguments(keyPathValues: Array<KeyPathValue>): Array<string> {
|
||||
if (keyPathValues.length === 0) {
|
||||
throw new Error('ERR wrong number of arguments for \'MSET\' command');
|
||||
}
|
||||
const args: string[] = keyPathValues.flatMap(({ key, path, value }) => [
|
||||
key,
|
||||
path,
|
||||
transformRedisJsonArgument(value)
|
||||
]);
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK' | null;
|
@@ -9,6 +9,7 @@ import * as DEL from './DEL';
|
||||
import * as FORGET from './FORGET';
|
||||
import * as GET from './GET';
|
||||
import * as MGET from './MGET';
|
||||
import * as MSET from './MSET';
|
||||
import * as MERGE from './MERGE';
|
||||
import * as NUMINCRBY from './NUMINCRBY';
|
||||
import * as NUMMULTBY from './NUMMULTBY';
|
||||
@@ -45,6 +46,8 @@ export default {
|
||||
merge: MERGE,
|
||||
MGET,
|
||||
mGet: MGET,
|
||||
MSET,
|
||||
mSet: MSET,
|
||||
NUMINCRBY,
|
||||
numIncrBy: NUMINCRBY,
|
||||
NUMMULTBY,
|
||||
|
Reference in New Issue
Block a user