
date age : int bio : Optional try : Customer ( first_name = "Andrew", last_name = "Brookins", email = "Not an email address!", join_date = datetime. But every Redis OM model is also a Pydantic model, so you can use Pydantic validators like EmailStr, Pattern, and many more for complex validations!įor example, because we used the EmailStr type for the email field, we'll get a validation error if we try to create a Customer with an invalid email address: import datetime from typing import Optional from pydantic import EmailStr, ValidationError from redis_om import HashModel class Customer ( HashModel ): first_name : str last_name : str email : EmailStr join_date : datetime. This validation ensures that fields like first_name, which the Customer model marked as a str, are always strings. Redis OM uses Pydantic to validate data based on the type annotations you assign to fields in a model class. Or, continue reading to see how Redis OM makes data validation a snap. Ready to learn more? Check out the getting started guide. save () # To retrieve this customer with its primary key, we use `Customer.get()`: assert Customer. pk ) # > "01FJM6PH661HCNNRC884H6K30C" # We can save the model to Redis by calling `save()`: andrew. today (), age = 38, bio = "Python developer, works at Redis, Inc." ) # The model generates a globally unique primary key automatically # without needing to talk to Redis. date age : int bio : Optional # First, we create a new `Customer` object: andrew = Customer ( first_name = "Andrew", last_name = "Brookins", email =, join_date = datetime. import datetime from typing import Optional from pydantic import EmailStr from redis_om import HashModel class Customer ( HashModel ): first_name : str last_name : str email : EmailStr join_date : datetime. Now that we have a Customer model, let's use it to save customer data to Redis. First, we create a Customer model: import datetime from typing import Optional from pydantic import EmailStr from redis_om import HashModel class Customer ( HashModel ): first_name : str last_name : str email : EmailStr join_date : datetime. Redis OM contains powerful declarative models that give you data validation, serialization, and persistence to Redis.Ĭheck out this example of modeling customer data with Redis OM.

✨ So How Do You Get RediSearch and RedisJSON?.Redis OM Python | Redis OM Node.js | Redis OM Spring | Redis OM.

Redis OM Python makes it easy to model Redis data in your Python applications. Object mapping, and more, for Redis and Python
