Skip to content

Commit 4a4d0b4

Browse files
author
Andrew Brookins
committed
Remove stub documentation in favor of GH Issues
1 parent cab1fc3 commit 4a4d0b4

9 files changed

+95
-179
lines changed

README.md

+7-10
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ span
3333
- [📇 Modeling Your Data](#-modeling-your-data)
3434
- [✓ Validating Data With Your Model](#-validating-data-with-your-model)
3535
- [🔎 Rich Queries and Embedded Models](#-rich-queries-and-embedded-models)
36+
- [Querying](#querying)
37+
- [Embedded Models](#embedded-models)
3638
- [💻 Installation](#-installation)
3739
- [📚 Documentation](#-documentation)
38-
- [⛏️ Troubleshooting](#-troubleshooting)
39-
- [✨ So, How Do You Get RediSearch and RedisJSON?](#-so-how-do-you-get-redisearch-and-redisjson)
40-
- [❤️ Contributing](#-contributing)
40+
- [⛏️ Troubleshooting](#-troubleshooting)
41+
- [✨ So How Do You Get RediSearch and RedisJSON?](#-so-how-do-you-get-redisearch-and-redisjson)
42+
- [❤️ Contributing](#-contributing)
4143
- [📝 License](#-license)
4244

4345
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -199,7 +201,7 @@ from redis_om import (
199201
)
200202
from redis_om import get_redis_connection
201203

202-
204+
203205
class Customer(HashModel):
204206
first_name: str
205207
last_name: str = Field(index=True)
@@ -235,8 +237,6 @@ These queries -- and more! -- are possible because **Redis OM manages indexes fo
235237

236238
Querying with this index features a rich expression syntax inspired by the Django ORM, SQLAlchemy, and Peewee. We think you'll enjoy it!
237239

238-
To learn more about how to query with Redis OM, see the [documentation on querying](docs/querying.md).
239-
****
240240
### Embedded Models
241241

242242
Redis OM can store and query **nested models** like any document database, with the speed and power you get from Redis. Let's see how this works.
@@ -292,8 +292,6 @@ Customer.find(Customer.address.city == "San Antonio",
292292
Customer.address.state == "TX")
293293
```
294294

295-
To learn more, read the [documentation on embedded models](docs/embedded.md).
296-
297295
## 💻 Installation
298296

299297
Installation is simple with `pip`, Poetry, or Pipenv.
@@ -314,8 +312,7 @@ The Redis OM documentation is available [here](docs/index.md).
314312

315313
If you run into trouble or have any questions, we're here to help!
316314

317-
First, check the [FAQ](docs/faq.md). If you don't find the answer there,
318-
hit us up on the [Redis Discord Server](http://discord.gg/redis).
315+
Hit us up on the [Redis Discord Server](http://discord.gg/redis) or [open an issue on GitHub](https://github.com/redis-developer/redis-om-python/issues/new).
319316

320317
## ✨ So How Do You Get RediSearch and RedisJSON?
321318

docs/connections.md

-3
This file was deleted.

docs/embedded_models.md

-54
This file was deleted.

docs/faq.md

-3
This file was deleted.

docs/fastapi_integration.md

+88-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## Introduction
44

5-
This section includes a complete example showing how to integrate Redis OM with FastAPI.
5+
Good news: Redis OM was specifically designed to integrate with FastAPI!
66

7-
Good news: Redis OM was **specifically designed to integrate with FastAPI**!
7+
This section includes a complete example showing how to integrate Redis OM with FastAPI.
88

99
## Concepts
1010

@@ -131,4 +131,89 @@ Get a copy of the value for "pk" and make another request to get that customer:
131131
You can also get a list of all customer PKs:
132132

133133
$ curl "http://localhost:8000/customers"
134-
{"customers":["01FM2G8EP38AVMH7PMTAJ123TA"]}
134+
{"customers":["01FM2G8EP38AVMH7PMTAJ123TA"]}
135+
136+
## Redsi OM with Asyncio
137+
138+
Redis OM is designed to work with asyncio, so you can use Redis OM models asynchronously within FastAPI applications.
139+
140+
The only difference is that you import the Redis OM models from the `aredis_om` module instead of the `redis_om` module.
141+
142+
Here is the previous FastAPI app, but using asyncio-compatible Redis OM code:
143+
144+
```python
145+
import datetime
146+
from typing import Optional
147+
148+
import aioredis
149+
150+
from fastapi import FastAPI, HTTPException
151+
from starlette.requests import Request
152+
from starlette.responses import Response
153+
154+
from fastapi_cache import FastAPICache
155+
from fastapi_cache.backends.redis import RedisBackend
156+
from fastapi_cache.decorator import cache
157+
158+
from pydantic import EmailStr
159+
160+
from aredis_om import HashModel, NotFoundError # <- Notice, we import from aredis_om
161+
from aredis_om import get_redis_connection
162+
163+
# This Redis instance is tuned for durability.
164+
REDIS_DATA_URL = "redis://localhost:6380"
165+
166+
# This Redis instance is tuned for cache performance.
167+
REDIS_CACHE_URL = "redis://localhost:6381"
168+
169+
170+
class Customer(HashModel):
171+
first_name: str
172+
last_name: str
173+
email: EmailStr
174+
join_date: datetime.date
175+
age: int
176+
bio: Optional[str]
177+
178+
179+
app = FastAPI()
180+
181+
182+
@app.post("/customer")
183+
async def save_customer(customer: Customer):
184+
# We can save the model to Redis by calling `save()`:
185+
return await customer.save() # <- We use await here
186+
187+
188+
@app.get("/customers")
189+
async def list_customers(request: Request, response: Response):
190+
# To retrieve this customer with its primary key, we use `Customer.get()`:
191+
return {"customers": await Customer.all_pks()} # <- We also use await here
192+
193+
194+
@app.get("/customer/{pk}")
195+
@cache(expire=10)
196+
async def get_customer(pk: str, request: Request, response: Response):
197+
# To retrieve this customer with its primary key, we use `Customer.get()`:
198+
try:
199+
return await Customer.get(pk) # <- And, finally, one more await!
200+
except NotFoundError:
201+
raise HTTPException(status_code=404, detail="Customer not found")
202+
203+
204+
@app.on_event("startup")
205+
async def startup():
206+
r = aioredis.from_url(REDIS_CACHE_URL, encoding="utf8",
207+
decode_responses=True)
208+
FastAPICache.init(RedisBackend(r), prefix="fastapi-cache")
209+
210+
# You can set the Redis OM URL using the REDIS_OM_URL environment
211+
# variable, or by manually creating the connection using your model's
212+
# Meta object.
213+
Customer.Meta.database = get_redis_connection(url=REDIS_DATA_URL,
214+
decode_responses=True)
215+
```
216+
217+
**NOTE:** The modules `redis_om` and `aredis_om` are identical in almost every
218+
way. The only difference is that the `aredis_om` returns coroutines that you must
219+
`await`.

docs/integrating.md

-3
This file was deleted.

docs/models_and_fields.md

-31
This file was deleted.

docs/querying.md

-67
This file was deleted.

docs/testing.md

-5
This file was deleted.

0 commit comments

Comments
 (0)