Skip to content

Commit fd81e54

Browse files
author
Andrew Brookins
committed
WIP on README
1 parent d7dd9d3 commit fd81e54

File tree

1 file changed

+63
-29
lines changed

1 file changed

+63
-29
lines changed

README.md

+63-29
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h1 align="center">Redis OM</h1>
22
<p align="center">
33
<p align="center">
4-
Objecting mapping and more, for Redis.
4+
Objecting mapping, and more, for Redis.
55
</p>
66
</p>
77

@@ -11,7 +11,7 @@
1111
[![License][license-image]][license-url]
1212
[![Build Status][ci-svg]][ci-url]
1313

14-
Redis OM is a library that helps you build modern Python applications with Redis.
14+
**Redis OM Python** makes it easy to model Redis data in your Python applications.
1515

1616
**Redis OM Python** | [Redis OM Node.js][redis-om-js] | [Redis OM Spring][redis-om-spring] | [Redis OM .NET][redis-om-dotnet]
1717

@@ -21,32 +21,41 @@ Redis OM is a library that helps you build modern Python applications with Redis
2121
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
2222
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
2323

24-
25-
- [Why Redis OM?](#why)
26-
- [Getting started](#getting-started)
27-
- [Installation](#installation)
28-
- [Documentation](#documentation)
29-
- [Troubleshooting](#troubleshooting)
30-
- [Contributing](#contributing)
31-
- [License](#license)
24+
- [💡 Why Redis OM?](#-why-redis-om)
25+
- [Starting Redis](#starting-redis)
26+
- [📇 Modeling your domain (and indexing it!)](#-modeling-your-domain-and-indexing-it)
27+
- [🔎 Querying](#-querying)
28+
- [Why this is important](#why-this-is-important)
29+
- [So how do you get RediSearch and RedisJSON?](#so-how-do-you-get-redisearch-and-redisjson)
30+
- [Why Redis OM?](#why)
31+
- [Getting started](#getting-started)
32+
- [Installation](#installation)
33+
- [Documentation](#documentation)
34+
- [Troubleshooting](#troubleshooting)
35+
- [Contributing](#contributing)
36+
- [License](#license)
3237

3338
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3439

3540
</details>
3641

37-
## ➡ Why Redis OM?
42+
## 💡 Why Redis OM?
43+
44+
Redis OM provides high-level abstractions for using Redis in Python, making it easy to model and query your Redis domain objects.
3845

39-
Redis OM is a library of high-level tools that help you build modern Python applications with Redis.
46+
This **preview** release contains the following features:
4047

41-
This *preview release* includes our first major component: a **declarative model class** backed by Redis.
48+
* Declarative object mapping for Redis objects
49+
* Declarative secondary-index generation
50+
* Fluent APIs for querying Redis
4251

4352
## 🏁 Getting started
4453

4554
### Object Mapping
4655

47-
With Redis OM, you get powerful data modeling, extensible data validation with [Pydantic](pydantic-url), and rich query expressions with a small amount of code.
56+
With Redis OM, you get powerful data modeling, extensible data validation with [Pydantic](pydantic-url), and rich query expressions.
4857

49-
Check out this example of data modeling and validation. First, we're going to create a `Customer` model that we can use to save data to Redis.
58+
Check out this example of how we'd model customer data with Redis OM. First, we're going to create a `Customer` model:
5059

5160
```python
5261
import datetime
@@ -68,12 +77,13 @@ class Customer(HashModel):
6877
bio: Optional[str]
6978
```
7079

71-
Here, we've defined a `Customer` model with the `HashModel` class from redis-om. This model will save data in Redis as a [Redis Hash](https://redis.io/topics/data-types).
80+
**NOTE**: Redis OM uses Python type annotations for data validation. See the _Data Validation_ section of this README for more details.
7281

73-
Next, let's see how Redis OM makes it easy to save and retrieve `Customer` data in Redis.
82+
Now that we have a `Customer` model, let's use it to save customer data to Redis.
83+
84+
First, we create a new `Customer` object:
7485

7586
```python
76-
# We can create a new Customer object:
7787
andrew = Customer(
7888
first_name="Andrew",
7989
last_name="Brookins",
@@ -82,25 +92,47 @@ andrew = Customer(
8292
age=38,
8393
bio="Python developer, works at Redis, Inc."
8494
)
95+
```
96+
The model generates a globally unique primary key automatically without needing to talk to Redis.
8597

86-
# The model generates a globally unique primary key automatically without
87-
# needing to talk to Redis.
98+
```python
8899
print(andrew.pk)
89-
# '01FJM6PH661HCNNRC884H6K30C'
100+
'01FJM6PH661HCNNRC884H6K30C'
101+
```
102+
103+
We can save the model to Redis by calling `save()`:
90104

91-
# We can save the model to Redis.
105+
```python
92106
andrew.save()
107+
```
108+
109+
To retrieve this customer with its primary key, we use `Customer.get()`:
93110

94-
# Now, we can retrieve this customer with its primary key:
111+
```python
95112
other_andrew = Customer.get('01FJM6PH661HCNNRC884H6K30C')
113+
```
114+
115+
Now let's see how Redis OM makes data validation a snap, thanks to [Pydantic](https://pydantic-docs.helpmanual.io/).
96116

97-
# The original model and this one pass an equality check.
98-
assert other_andrew == andrew
117+
### Data Validation
118+
119+
When you create a model with Redis OM, you define fields and give them type annotations. As a refresher, take a look at the `Customer` model we already built:
120+
121+
```python
122+
class Customer(HashModel):
123+
first_name: str
124+
last_name: str
125+
email: EmailStr
126+
join_date: datetime.date
127+
age: int
128+
bio: Optional[str]
99129
```
100130

101-
Now, let's talk about **validation**. Did you notice the type annotation for the `email` field was `EmailStr`?
131+
Redis OM uses [Pydantic](pydantic-url) behind the scenes to validate data at runtime, based on the model's type annotations.
132+
133+
This validation works for basic cases, like ensuring that `first_name` is always a string. But every Redis OM model is also a Pydantic model, so you can use existing Pydantic validators like `EmailStr`, `Pattern`, and many more for complex validation!
102134

103-
`EmailStr` is a [Pydantic field validator](https://pydantic-docs.helpmanual.io/usage/types/). Because every Redis OM model is also a Pydantic model, you can use Pydantic validators like `EmailStr`, `Pattern`, and many more!
135+
#### A Demo
104136

105137
Let's see what happens if we try to instantiate our `Customer` class with an invalid email address.
106138

@@ -140,9 +172,11 @@ andrew.save()
140172
# value is not a valid email address (type=value_error.email)
141173
```
142174

143-
Data modeling, validation, and persistent to Redis all work regardless of where you run Redis. But can we do more?
175+
Data modeling, validation, and persisting to Redis all work regardless of how you run Redis.
176+
177+
However, Redis OM will take your Python applications to the next level if you're using the RediSearch and RedisJSON modules in your Redis deployment. Next, we'll talk about the **rich query expressions** and **embedded models** that Redis OM gives you with those Redis modules.
144178

145-
Yes, we can! Next, we'll talk about the **rich query expressions** and **embedded models** that Redis OM gives you when you're using the RediSearch and RedisJSON Redis modules.
179+
**TIP**: *Wait, what's a Redis module?* If you aren't familiar with Redis modules, review the *RediSearch and RedisJSON* section of this README.
146180

147181
### Querying
148182
Querying uses a rich expression syntax inspired by the Django ORM, SQLAlchemy, and Peewee.

0 commit comments

Comments
 (0)