@redis/json 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -12
- package/dist/commands/MERGE.d.ts +4 -0
- package/dist/commands/MERGE.js +9 -0
- package/dist/commands/MSET.d.ts +11 -0
- package/dist/commands/MSET.js +18 -0
- package/dist/commands/RESP.d.ts +1 -1
- package/dist/commands/STRAPPEND.d.ts +2 -2
- package/dist/commands/index.d.ts +7 -1
- package/dist/commands/index.js +6 -0
- package/package.json +18 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @redis/json
|
|
2
2
|
|
|
3
|
-
This package provides support for the [RedisJSON](https://
|
|
3
|
+
This package provides support for the [RedisJSON](https://redis.io/docs/stack/json/) module, which adds JSON as a native data type to Redis. It extends the [Node Redis client](https://github.com/redis/node-redis) to include functions for each of the RedisJSON commands.
|
|
4
4
|
|
|
5
5
|
To use these extra commands, your Redis server must have the RedisJSON module installed.
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ For a complete example, see [`managing-json.js`](https://github.com/redis/node-r
|
|
|
10
10
|
|
|
11
11
|
### Storing JSON Documents in Redis
|
|
12
12
|
|
|
13
|
-
The [`JSON.SET`](https://
|
|
13
|
+
The [`JSON.SET`](https://redis.io/commands/json.set/) command stores a JSON value at a given JSON Path in a Redis key.
|
|
14
14
|
|
|
15
15
|
Here, we'll store a JSON document in the root of the Redis key "`mydoc`":
|
|
16
16
|
|
|
@@ -37,11 +37,11 @@ await client.json.set('noderedis:jsondata', '$', {
|
|
|
37
37
|
});
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
For more information about RedisJSON's path syntax, [check out the documentation](https://
|
|
40
|
+
For more information about RedisJSON's path syntax, [check out the documentation](https://redis.io/docs/stack/json/path/).
|
|
41
41
|
|
|
42
42
|
### Retrieving JSON Documents from Redis
|
|
43
43
|
|
|
44
|
-
With RedisJSON, we can retrieve all or part(s) of a JSON document using the [`JSON.GET`]() command and one or more JSON Paths. Let's get the name and age of one of the pets:
|
|
44
|
+
With RedisJSON, we can retrieve all or part(s) of a JSON document using the [`JSON.GET`](https://redis.io/commands/json.get/) command and one or more JSON Paths. Let's get the name and age of one of the pets:
|
|
45
45
|
|
|
46
46
|
```javascript
|
|
47
47
|
const results = await client.json.get('noderedis:jsondata', {
|
|
@@ -62,19 +62,19 @@ const results = await client.json.get('noderedis:jsondata', {
|
|
|
62
62
|
|
|
63
63
|
RedisJSON includes commands that can atomically update values in a JSON document, in place in Redis without having to first retrieve the entire document.
|
|
64
64
|
|
|
65
|
-
Using the [`JSON.NUMINCRBY`](https://
|
|
65
|
+
Using the [`JSON.NUMINCRBY`](https://redis.io/commands/json.numincrby/) command, we can update the age of one of the pets like this:
|
|
66
66
|
|
|
67
67
|
```javascript
|
|
68
68
|
await client.json.numIncrBy('noderedis:jsondata', '.pets[1].age', 1);
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
And we can add a new object to the pets array with the [`JSON.ARRAPPEND`](https://
|
|
71
|
+
And we can add a new object to the pets array with the [`JSON.ARRAPPEND`](https://redis.io/commands/json.arrappend/) command:
|
|
72
72
|
|
|
73
73
|
```javascript
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
await client.json.arrAppend('noderedis:jsondata', '.pets', {
|
|
75
|
+
name: 'Robin',
|
|
76
|
+
species: 'bird',
|
|
77
|
+
age: 1,
|
|
78
|
+
isMammal: false
|
|
79
|
+
});
|
|
80
80
|
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
6
|
+
function transformArguments(key, path, json) {
|
|
7
|
+
return ['JSON.MERGE', key, path, (0, _1.transformRedisJsonArgument)(json)];
|
|
8
|
+
}
|
|
9
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RedisJSON } from '.';
|
|
2
|
+
import { RedisCommandArgument } from '@redis/client/dist/lib/commands';
|
|
3
|
+
export declare const FIRST_KEY_INDEX = 1;
|
|
4
|
+
interface JsonMSetItem {
|
|
5
|
+
key: RedisCommandArgument;
|
|
6
|
+
path: RedisCommandArgument;
|
|
7
|
+
value: RedisJSON;
|
|
8
|
+
}
|
|
9
|
+
export declare function transformArguments(items: Array<JsonMSetItem>): Array<string>;
|
|
10
|
+
export declare function transformReply(): 'OK';
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
6
|
+
function transformArguments(items) {
|
|
7
|
+
const args = new Array(1 + items.length * 3);
|
|
8
|
+
args[0] = 'JSON.MSET';
|
|
9
|
+
let argsIndex = 1;
|
|
10
|
+
for (let i = 0; i < items.length; i++) {
|
|
11
|
+
const item = items[i];
|
|
12
|
+
args[argsIndex++] = item.key;
|
|
13
|
+
args[argsIndex++] = item.path;
|
|
14
|
+
args[argsIndex++] = (0, _1.transformRedisJsonArgument)(item.value);
|
|
15
|
+
}
|
|
16
|
+
return args;
|
|
17
|
+
}
|
|
18
|
+
exports.transformArguments = transformArguments;
|
package/dist/commands/RESP.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const FIRST_KEY_INDEX = 1;
|
|
2
2
|
export declare function transformArguments(key: string, path?: string): Array<string>;
|
|
3
|
-
|
|
3
|
+
type RESPReply = Array<string | number | RESPReply>;
|
|
4
4
|
export declare function transformReply(): RESPReply;
|
|
5
5
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const FIRST_KEY_INDEX = 1;
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type AppendArguments = [key: string, append: string];
|
|
3
|
+
type AppendWithPathArguments = [key: string, path: string, append: string];
|
|
4
4
|
export declare function transformArguments(...[key, pathOrAppend, append]: AppendArguments | AppendWithPathArguments): Array<string>;
|
|
5
5
|
export declare function transformReply(): number | Array<number>;
|
|
6
6
|
export {};
|
package/dist/commands/index.d.ts
CHANGED
|
@@ -8,7 +8,9 @@ import * as DEBUG_MEMORY from './DEBUG_MEMORY';
|
|
|
8
8
|
import * as DEL from './DEL';
|
|
9
9
|
import * as FORGET from './FORGET';
|
|
10
10
|
import * as GET from './GET';
|
|
11
|
+
import * as MERGE from './MERGE';
|
|
11
12
|
import * as MGET from './MGET';
|
|
13
|
+
import * as MSET from './MSET';
|
|
12
14
|
import * as NUMINCRBY from './NUMINCRBY';
|
|
13
15
|
import * as NUMMULTBY from './NUMMULTBY';
|
|
14
16
|
import * as OBJKEYS from './OBJKEYS';
|
|
@@ -39,8 +41,12 @@ declare const _default: {
|
|
|
39
41
|
forget: typeof FORGET;
|
|
40
42
|
GET: typeof GET;
|
|
41
43
|
get: typeof GET;
|
|
44
|
+
MERGE: typeof MERGE;
|
|
45
|
+
merge: typeof MERGE;
|
|
42
46
|
MGET: typeof MGET;
|
|
43
47
|
mGet: typeof MGET;
|
|
48
|
+
MSET: typeof MSET;
|
|
49
|
+
mSet: typeof MSET;
|
|
44
50
|
NUMINCRBY: typeof NUMINCRBY;
|
|
45
51
|
numIncrBy: typeof NUMINCRBY;
|
|
46
52
|
NUMMULTBY: typeof NUMMULTBY;
|
|
@@ -67,7 +73,7 @@ interface RedisJSONObject {
|
|
|
67
73
|
[key: string]: RedisJSON;
|
|
68
74
|
[key: number]: RedisJSON;
|
|
69
75
|
}
|
|
70
|
-
export
|
|
76
|
+
export type RedisJSON = null | boolean | number | string | Date | RedisJSONArray | RedisJSONObject;
|
|
71
77
|
export declare function transformRedisJsonArgument(json: RedisJSON): string;
|
|
72
78
|
export declare function transformRedisJsonReply(json: string): RedisJSON;
|
|
73
79
|
export declare function transformRedisJsonNullReply(json: string | null): RedisJSON | null;
|
package/dist/commands/index.js
CHANGED
|
@@ -11,7 +11,9 @@ const DEBUG_MEMORY = require("./DEBUG_MEMORY");
|
|
|
11
11
|
const DEL = require("./DEL");
|
|
12
12
|
const FORGET = require("./FORGET");
|
|
13
13
|
const GET = require("./GET");
|
|
14
|
+
const MERGE = require("./MERGE");
|
|
14
15
|
const MGET = require("./MGET");
|
|
16
|
+
const MSET = require("./MSET");
|
|
15
17
|
const NUMINCRBY = require("./NUMINCRBY");
|
|
16
18
|
const NUMMULTBY = require("./NUMMULTBY");
|
|
17
19
|
const OBJKEYS = require("./OBJKEYS");
|
|
@@ -42,8 +44,12 @@ exports.default = {
|
|
|
42
44
|
forget: FORGET,
|
|
43
45
|
GET,
|
|
44
46
|
get: GET,
|
|
47
|
+
MERGE,
|
|
48
|
+
merge: MERGE,
|
|
45
49
|
MGET,
|
|
46
50
|
mGet: MGET,
|
|
51
|
+
MSET,
|
|
52
|
+
mSet: MSET,
|
|
47
53
|
NUMINCRBY,
|
|
48
54
|
numIncrBy: NUMINCRBY,
|
|
49
55
|
NUMMULTBY,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redis/json",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -18,12 +18,24 @@
|
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
20
20
|
"@redis/test-utils": "*",
|
|
21
|
-
"@types/node": "^
|
|
21
|
+
"@types/node": "^20.6.2",
|
|
22
22
|
"nyc": "^15.1.0",
|
|
23
|
-
"release-it": "^
|
|
23
|
+
"release-it": "^16.1.5",
|
|
24
24
|
"source-map-support": "^0.5.21",
|
|
25
25
|
"ts-node": "^10.9.1",
|
|
26
|
-
"typedoc": "^0.
|
|
27
|
-
"typescript": "^
|
|
28
|
-
}
|
|
26
|
+
"typedoc": "^0.25.1",
|
|
27
|
+
"typescript": "^5.2.2"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git://github.com/redis/node-redis.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/redis/node-redis/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/redis/node-redis/tree/master/packages/json",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"redis",
|
|
39
|
+
"RedisJSON"
|
|
40
|
+
]
|
|
29
41
|
}
|