-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added MSET command MSET command added. Requires all keys to have the same JSON Path, which might fit most use cases, but is a limitation. Optionally we could make the path an array as well to support all use cases. * change JSON.MSET signature, add to json command object, fix tests * its `item.value`, not `item.json`.. * Update MSET.ts Removed unused RedisCommandArguments --------- Co-authored-by: Leibale Eidelman <[email protected]>
- Loading branch information
1 parent
26b9e6d
commit 5a10826
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters