You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/howtos/redisjson/using-python/index-usingpython.mdx
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ sidebar_label: RedisJSON and Python
5
5
slug: /howtos/redisjson/using-python
6
6
---
7
7
8
-
[RedisJSON](https://oss.redis.com/redisjson/) is a source-available Redis module that lets you store, manipulate, and query JSON documents in Redis. The standard Redis Python client (v4.0 or greater) supports all of the feature of RedisJSON, and in this tutorial, we'll see how to use them.
8
+
[RedisJSON](https://oss.redis.com/redisjson/) is a source-available Redis module that lets you store, manipulate, and query JSON documents in Redis. The standard Redis Python client (v4.0 or greater) supports all of the features of RedisJSON, and in this tutorial, we'll see how to get started with them.
9
9
10
10
## Getting started with RedisJSON
11
11
@@ -33,7 +33,7 @@ Ensure that you're running RedisJSON v2.0 or greater (here indicated as `20004`)
33
33
34
34
You'll need `redis-py` version 4.0 or later. If you're using `pipenv`, you can install the client library like so:
35
35
36
-
```
36
+
```bash
37
37
pipenv install redis
38
38
```
39
39
@@ -51,8 +51,8 @@ Let's consider a simple JSON document structure representing a user:
51
51
```
52
52
{
53
53
"name": "Jane",
54
-
"age": 25,
55
-
"location: "USA"
54
+
"age": 33,
55
+
"location: "Chawton"
56
56
}
57
57
```
58
58
@@ -80,28 +80,28 @@ In the code above, we first connect to Redis and store a reference to the connec
80
80
81
81
Next, we create a Python dictionary to represent a person object.
82
82
83
-
And finally, we store the object in Redis using the `json().set()` method. The first argument, `person:1` is the name of the key that will store the JSON. The second argument is a JSON path. We use `Path.rootPath()`, as this is a new object. Finally, we pass in the Python dictionary, which will be serialized to JSON.
83
+
And finally, we store the object in Redis using the `json().set()` method. The first argument, `person:1` is the name of the key that will reference the JSON. The second argument is a JSON path. We use `Path.rootPath()`, as this is a new object. Finally, we pass in the Python dictionary, which will be serialized to JSON.
84
84
85
-
To retrieve the JSON object, we run `json().get()`, passing the key. The result is the Python dictionary we passed in.
85
+
To retrieve the JSON object, we run `json().get()`, passing in the key. The result is a Python dictionary representing the JSON object stored in Redis.
86
86
87
87
### Run the code
88
88
89
-
If you copy the code above in a file called `main.py`, you can run the code like so:
89
+
If you copy the code above into a file called `main.py`, you can run the code like so:
90
90
91
91
```bash
92
92
$ pipenv python run main.py
93
-
93
+
```
94
94
95
95
## Verify that the JSON document has been added to Redis
96
96
97
-
Start `redis-cli` to connect to your Redis instance. The run the following command:
97
+
Start `redis-cli` to connect to your Redis instance. Then run the following command:
0 commit comments