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/getting_started.md
+45-30Lines changed: 45 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ Windows users can also use Docker. See the next section on running Redis with Do
37
37
38
38
### Running Redis With Docker
39
39
40
-
Instead of installing Redis manually or with a package manager, you can run Redis with Docker. The official Redis Docker image is hosted on [Docker Hub](https://hub.docker.com/_/redis).
40
+
Instead of installing Redis manually or with a package manager, you can run Redis with Docker. The official Redis Docker image is hosted on [Docker Hub](https://hub.docker.com/_/redis).
41
41
42
42
**TIP:** If you plan on using Docker, we recommend the [redismod](https://hub.docker.com/r/redislabs/redismod) image because it includes the RediSearch and RedisJSON modules.
43
43
@@ -51,10 +51,9 @@ The easiest way to run these Redis modules during local development is to use th
51
51
52
52
You can quickly start Redis with the redismod Docker image by running the following command:
53
53
54
-
docker run -d -p 6379:6379 redislabs/redismod
55
-
54
+
docker run -d -p 6379:6379 redislabs/redismod
56
55
**TIP:** The `-d` option runs Redis in the background.
57
-
56
+
58
57
For other installation methods, follow the "Quick Start" guides on both modules' home pages for alternative installation methods.
59
58
60
59
## Start Redis
@@ -67,41 +66,38 @@ The command you use to start Redis will depend on how you installed it.
67
66
68
67
If you installed Redis using `apt`, start it with the `systemctl` command:
69
68
70
-
sudo systemctl restart redis.service
71
-
69
+
sudo systemctl restart redis.service
72
70
Otherwise, you can start the server manually:
73
71
74
-
redis-server start
72
+
redis-server start
75
73
76
74
### macOS with Homebrew
77
-
78
-
brew services start redis
79
-
75
+
76
+
brew services start redis
77
+
80
78
### Docker
81
79
82
80
The command to start Redis with Docker depends on the image you've chosen to use.
83
81
84
82
#### Docker with the redismod image (recommended)
85
83
86
-
docker run -d -p 6379:6379 redislabs/redismod
84
+
docker run -d -p 6379:6379 redislabs/redismod
87
85
88
86
### Docker iwth the redis image
89
87
90
-
docker run -d -p 6379:6379 redis
88
+
docker run -d -p 6379:6379 redis
91
89
92
90
## Installing Redis OM
93
91
94
92
You can install Redis OM with `pip` by running the following command:
95
93
96
-
pip install redis-om
97
-
94
+
pip install redis-om
98
95
Or, if you're using Poetry, you can install Redis OM with the following command:
99
96
100
-
poetry install redis-om
101
-
97
+
poetry install redis-om
102
98
With Pipenv, the command is:
103
99
104
-
pipenv install redis-om
100
+
pipenv install redis-om
105
101
106
102
## Setting the Redis URL Environment Variable
107
103
@@ -113,19 +109,16 @@ However, if you configured Redis to run on a different port, or if you're using
113
109
114
110
The `REDIS_URL` environment variable follows the redis-py URL format:
For more details about how to connect to Redis with Redis OM, see the [connections documentation](connections.md).
130
123
131
124
### Redis Cluster Support
@@ -134,7 +127,7 @@ Redis OM supports connecting to Redis Cluster, but this preview release does not
134
127
135
128
See the [connections documentation](connections.md) for examples of connecting to Redis Cluster.
136
129
137
-
Support for connecting to Redis Cluster via `REDIS_URL` will be added in a future release.
130
+
Support for connecting to Redis Cluster via `REDIS_URL` will be added in a future release.
138
131
139
132
## Defining a Model
140
133
@@ -167,7 +160,7 @@ Let's dig into these two details a bit more.
167
160
168
161
### The HashModel Class
169
162
170
-
When you subclass `HashModel`, your subclass is both a Redis OM model, with methods for saving data to Redis, *and* a Pydantic model.
163
+
When you subclass `HashModel`, your subclass is both a Redis OM model, with methods for saving data to Redis, *and* a Pydantic model.
171
164
172
165
This means that you can use Pydantic field validations with your Redis OM models, which we'll cover later, when we talk about validation. But this also means you can use Redis OM models anywhere you would use a Pydantic model, like in your FastAPI applications. 🤯
173
166
@@ -231,7 +224,7 @@ class Customer(HashModel):
231
224
join_date: datetime.date
232
225
age: int
233
226
bio: Optional[str]
234
-
```
227
+
```
235
228
236
229
Now we can create `Customer` objects with or without the `bio` field.
237
230
@@ -247,7 +240,7 @@ class Customer(HashModel):
247
240
join_date: datetime.date
248
241
age: int
249
242
bio: Optional[str] ="Super dope"
250
-
```
243
+
```
251
244
252
245
Now, if we create a `Customer` object without a `bio` field, it will use the default value.
The model will then save this default value to Redis the next time you call `save()`.
260
+
261
+
### Automatic Primary Keys
262
+
263
+
Models generate a globally unique primary key automatically without needing to talk to Redis.
264
+
265
+
```python
266
+
print(andrew.pk)
267
+
'01FJM6PH661HCNNRC884H6K30C'
268
+
```
269
+
270
+
The ID is available *before* you save the model.
271
+
272
+
The default ID generation function creates [ULIDs](https://github.com/ulid/spec), though you can change the function that generates the primary key for models if you'd like to use a different kind of primary key.
273
+
266
274
## Saving Models
267
275
276
+
We can save the model to Redis by calling `save()`:
277
+
278
+
```python
279
+
andrew.save()
280
+
```
281
+
268
282
## Examining Your Data In Redis
269
283
270
284
## Validating Data
@@ -274,5 +288,6 @@ print(andrew.bio)
274
288
Now that you know the basics of working with Redis OM, continue on for all the nitty-gritty details about [models and fields](validation.md).
0 commit comments