Skip to content

Commit 6955225

Browse files
chayimYaraslauZhylkodvora-h
authored
Updating documentation to use redis.asyncio (#447)
* removing aioredis from documentation * fix: proper python 3.11 support (#446) * fix: propper python 3.11 support * fix tox config * wider python 3.x support * Update ci.yml Co-authored-by: dvora-h <[email protected]> * Add poetry.lock to .gitignore (#457) * Add poetry.lock to .gitignore * remove poetry.lock * PR comments readme update Co-authored-by: Yaraslau Zhylko <[email protected]> Co-authored-by: dvora-h <[email protected]>
1 parent 1aa619e commit 6955225

File tree

6 files changed

+22
-26
lines changed

6 files changed

+22
-26
lines changed

.github/wordlist.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ TOC
2727
ULIDs
2828
UlidPrimaryKey
2929
WSL
30-
aioredis
3130
async
3231
asyncio
3332
cls

docs/connections.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Customer(HashModel):
8080
database = redis
8181
```
8282

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.
8484

8585
You can also manually construct a client object:
8686

docs/fastapi_integration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Let's look at an example FastAPI app that uses Redis OM.
3636
import datetime
3737
from typing import Optional
3838

39-
import aioredis
39+
import redis
4040

4141
from fastapi import FastAPI, HTTPException
4242
from starlette.requests import Request
@@ -94,7 +94,7 @@ async def get_customer(pk: str, request: Request, response: Response):
9494

9595
@app.on_event("startup")
9696
async def startup():
97-
r = aioredis.from_url(REDIS_CACHE_URL, encoding="utf8",
97+
r = redis.asyncio.from_url(REDIS_CACHE_URL, encoding="utf8",
9898
decode_responses=True)
9999
FastAPICache.init(RedisBackend(r), prefix="fastapi-cache")
100100

@@ -148,7 +148,7 @@ Here is the previous FastAPI app, but using asyncio-compatible Redis OM code:
148148
import datetime
149149
from typing import Optional
150150

151-
import aioredis
151+
import redis
152152

153153
from fastapi import FastAPI, HTTPException
154154
from starlette.requests import Request
@@ -206,7 +206,7 @@ async def get_customer(pk: str, request: Request, response: Response):
206206

207207
@app.on_event("startup")
208208
async def startup():
209-
r = aioredis.from_url(REDIS_CACHE_URL, encoding="utf8",
209+
r = redis.asyncio.from_url(REDIS_CACHE_URL, encoding="utf8",
210210
decode_responses=True)
211211
FastAPICache.init(RedisBackend(r), prefix="fastapi-cache")
212212

docs/getting_started.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ Python 3.7.0
1919

2020
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.
2121

22+
This library requires [redis-py](https://pypi.org/project/redis) version 4.2.0 or higher.
23+
2224
## Redis
2325

2426
Redis OM saves data in Redis, so you will need Redis installed and running to complete this tutorial.
2527

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+
2634
### Downloading Redis
2735

2836
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
3341

3442
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.
3543

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.
4745

4846
## Recommended: RediSearch and RedisJSON
4947

docs/models.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ from redis_om import HashModel
4545
class Customer(HashModel):
4646
first_name: str
4747
last_name: str
48-
48+
4949
class Meta:
5050
global_key_prefix = "customer-dashboard"
5151
```
@@ -94,15 +94,15 @@ class BaseModel(HashModel, ABC):
9494
global_key_prefix = "customer-dashboard"
9595
database = redis
9696

97-
97+
9898
class Customer(BaseModel):
9999
first_name: str
100100
last_name: str
101-
101+
102102
class Meta:
103103
database = other_redis
104104

105-
105+
106106
print(Customer.global_key_prefix)
107107
# > "customer-dashboard"
108108
```
@@ -122,11 +122,11 @@ Here is a table of the settings available in the Meta object and what they contr
122122
| global_key_prefix | A string prefix applied to every Redis key that the model manages. This could be something like your application's name. | "" |
123123
| 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. | "" |
124124
| 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(). |
126126
| 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 |
127127
| 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" |
128128
| 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" |
130130
## Configuring Pydantic
131131

132132
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
141141

142142
class Customer(HashModel):
143143
# ... Fields ...
144-
144+
145145
class Config:
146146
orm_mode = True
147147
arbitrary_types_allowed = True
@@ -177,7 +177,7 @@ So, in short, if you want to use container types, use `JsonModel`.
177177
Good news! Container types _are_ supported with `JsonModel`.
178178

179179
We will use Pydantic's JSON serialization and encoding to serialize your `JsonModel` and save it in Redis.
180-
180+
181181
### Default Values
182182

183183
Fields can have default values. You set them by assigning a value to a field.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ include=[
3737
[tool.poetry.dependencies]
3838
python = ">=3.7,<4.0"
3939
redis = ">=3.5.3,<5.0.0"
40-
aioredis = "^2.0.0"
4140
pydantic = "^1.10.2"
4241
click = "^8.0.1"
4342
pptree = "^3.1"

0 commit comments

Comments
 (0)