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/connections.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ class Customer(HashModel):
80
80
database = redis
81
81
```
82
82
83
-
The `get_redis_connection()` function is a Redis OM helper that passes keyword arguments to either `aioredis.Redis.from_url()` or `redis.Redis.from_url()`, depending on whether you are using Redis OM in async or sync mode.
83
+
The `get_redis_connection()` function is a Redis OM helper that passes keyword arguments to either `redis.asyncio.Redis.from_url()` or `redis.Redis.from_url()`, depending on whether you are using Redis OM in async or sync mode.
Copy file name to clipboardExpand all lines: docs/getting_started.md
+9-11Lines changed: 9 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -19,10 +19,18 @@ Python 3.7.0
19
19
20
20
If you don't have Python installed, you can download it from [Python.org](https://www.python.org/downloads/), use [pyenv](https://github.com/pyenv/pyenv), or install Python with your operating system's package manager.
21
21
22
+
This library requires [redis-py](https://pypi.org/project/redis) version 4.2.0 or higher.
23
+
22
24
## Redis
23
25
24
26
Redis OM saves data in Redis, so you will need Redis installed and running to complete this tutorial.
25
27
28
+
We recommend the [redis-stack](https://hub.docker.com/r/redis/redis-stack) image because it includes Redis capabilities that this library uses to provide extra features. Later sections of this guide will provide more detail about these features.
29
+
30
+
You can also use the official Redis Docker image, which is hosted on [Docker Hub](https://hub.docker.com/_/redis). However this does not include the Search and JSON modules required to store JSON models and use the `find` query interface.
31
+
32
+
**NOTE**: We'll talk about how to actually start Redis with Docker when we discuss _running_ Redis later in this guide.
33
+
26
34
### Downloading Redis
27
35
28
36
The latest version of Redis is available from [Redis.io](https://redis.io/). You can also install Redis with your operating system's package manager.
@@ -33,17 +41,7 @@ The latest version of Redis is available from [Redis.io](https://redis.io/). You
33
41
34
42
Redis doesn't run directly on Windows, but you can use Windows Subsystem for Linux (WSL) to run Redis. See [our video on YouTube](https://youtu.be/_nFwPTHOMIY) for a walk-through.
35
43
36
-
Windows users can also use Docker. See the next section on running Redis with Docker for more information.
37
-
38
-
### Using Redis With Docker
39
-
40
-
Instead of installing Redis manually or with a package manager, you can run Redis with Docker.
41
-
42
-
We recommend the [redis-stack](https://hub.docker.com/r/redis/redis-stack) image because it includes Redis modules that Redis OM can use to give you extra features. Later sections of this guide will provide more detail about these features.
43
-
44
-
You can also use the official Redis Docker image, which is hosted on [Docker Hub](https://hub.docker.com/_/redis). However this does not include the Search and JSON modules required to store JSON models and use the `find` query interface.
45
-
46
-
**NOTE**: We'll talk about how to actually start Redis with Docker when we discuss _running_ Redis later in this guide.
44
+
Windows users can also use the Docker image mentioned previously.
Copy file name to clipboardExpand all lines: docs/models.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -45,7 +45,7 @@ from redis_om import HashModel
45
45
classCustomer(HashModel):
46
46
first_name: str
47
47
last_name: str
48
-
48
+
49
49
classMeta:
50
50
global_key_prefix ="customer-dashboard"
51
51
```
@@ -94,15 +94,15 @@ class BaseModel(HashModel, ABC):
94
94
global_key_prefix ="customer-dashboard"
95
95
database = redis
96
96
97
-
97
+
98
98
classCustomer(BaseModel):
99
99
first_name: str
100
100
last_name: str
101
-
101
+
102
102
classMeta:
103
103
database = other_redis
104
104
105
-
105
+
106
106
print(Customer.global_key_prefix)
107
107
# > "customer-dashboard"
108
108
```
@@ -122,11 +122,11 @@ Here is a table of the settings available in the Meta object and what they contr
122
122
| global_key_prefix | A string prefix applied to every Redis key that the model manages. This could be something like your application's name. | "" |
123
123
| model_key_prefix | A string prefix applied to the Redis key representing every model. For example, the Redis Hash key for a HashModel. This prefix is also added to the redisearch index created for every model with indexed fields. | "" |
124
124
| primary_key_pattern | A format string producing the base string for a Redis key representing this model. This string should accept a "pk" format argument. **Note:** This is a "new style" format string, which will be called with `.format()`. | "{pk}" |
125
-
| database |An aioredis.Redis or redis.Redis client instance that the model will use to communicate with Redis. | A new instance created with connections.get_redis_connection(). |
125
+
| database |A redis.asyncio.Redis or redis.Redis client instance that the model will use to communicate with Redis. | A new instance created with connections.get_redis_connection(). |
126
126
| primary_key_creator_cls | A class that adheres to the PrimaryKeyCreator protocol, which Redis OM will use to create a primary key for a new model instance. | UlidPrimaryKey |
127
127
| index_name | The RediSearch index name to use for this model. Only used if at least one of the model's fields are marked as indexable (`index=True`). | "{global_key_prefix}:{model_key_prefix}:index" |
128
128
| embedded | Whether or not this model is "embedded." Embedded models are not included in migrations that create and destroy indexes. Instead, their indexed fields are included in the index for the parent model. **Note**: Only `JsonModel` can have embedded models. | False |
129
-
| encoding | The default encoding to use for strings. This encoding is given to redis-py or aioredis at the connection level. In both cases, Redis OM will decode binary strings from Redis using your chosen encoding. | "utf-8" |
129
+
| encoding | The default encoding to use for strings. This encoding is given to redis-py at the connection level. In both cases, Redis OM will decode binary strings from Redis using your chosen encoding. | "utf-8" |
130
130
## Configuring Pydantic
131
131
132
132
Every Redis OM model is also a Pydantic model, so in addition to configuring Redis OM behavior with the Meta object, you can control Pydantic configuration via the Config object within a model class.
@@ -141,7 +141,7 @@ from redis_om import HashModel
141
141
142
142
classCustomer(HashModel):
143
143
# ... Fields ...
144
-
144
+
145
145
classConfig:
146
146
orm_mode =True
147
147
arbitrary_types_allowed =True
@@ -177,7 +177,7 @@ So, in short, if you want to use container types, use `JsonModel`.
177
177
Good news! Container types _are_ supported with `JsonModel`.
178
178
179
179
We will use Pydantic's JSON serialization and encoding to serialize your `JsonModel` and save it in Redis.
180
-
180
+
181
181
### Default Values
182
182
183
183
Fields can have default values. You set them by assigning a value to a field.
0 commit comments