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

some cleanups

This commit is contained in:
Leibale
2024-02-05 11:18:27 -05:00
parent 8f3a276509
commit 8340a9e830
21 changed files with 593 additions and 1341 deletions

View File

@@ -1,12 +1,14 @@
# @redis/json
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.
This package provides support for the [RedisJSON](https://redis.io/docs/data-types/json/) module, which adds JSON as a native data type to Redis.
To use these extra commands, your Redis server must have the RedisJSON module installed.
Should be used with [`redis`/`@redis/client`](https://github.com/redis/node-redis).
:warning: To use these extra commands, your Redis server must have the RedisJSON module installed.
## Usage
For a complete example, see [`managing-json.js`](https://github.com/redis/node-redis/blob/master/examples/managing-json.js) in the Node Redis examples folder.
For a complete example, see [`managing-json.js`](https://github.com/redis/node-redis/blob/master/examples/managing-json.js) in the [examples folder](https://github.com/redis/node-redis/tree/master/examples).
### Storing JSON Documents in Redis
@@ -15,33 +17,27 @@ The [`JSON.SET`](https://redis.io/commands/json.set/) command stores a JSON valu
Here, we'll store a JSON document in the root of the Redis key "`mydoc`":
```javascript
import { createClient } from 'redis';
...
await client.json.set('noderedis:jsondata', '$', {
name: 'Roberta McDonald',
pets: [
{
pets: [{
name: 'Rex',
species: 'dog',
age: 3,
isMammal: true
},
{
}, {
name: 'Goldie',
species: 'fish',
age: 2,
isMammal: false
}
]
}]
});
```
For more information about RedisJSON's path syntax, [check out the documentation](https://redis.io/docs/stack/json/path/).
For more information about RedisJSON's path syntax, [check out the documentation](https://redis.io/docs/data-types/json/path/).
### Retrieving JSON Documents from Redis
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:
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:
```javascript
const results = await client.json.get('noderedis:jsondata', {

View File

@@ -17,6 +17,9 @@
"devDependencies": {
"@redis/test-utils": "*"
},
"engines": {
"node": ">= 18"
},
"repository": {
"type": "git",
"url": "git://github.com/redis/node-redis.git"