This package provides a simple model structure for redis based storage.
Project description
Redis Models
This package provides a simple model structure for redis based storage. It acts like an ORM and allows you to create models with validation.
Installation
pip install redis_models
Usage
First, you need to create your model. It's similar to Pydantic models, or built-in dataclass.
from redis_models.models import RedisModel
class MyUserModel(RedisModel):
name: str
age: int
class Meta:
redis_url = "redis://localhost:6379/0"
Let's create a User object
user = User(name="John Doe", age=30)
Let's try creating an object that does not fit to the definition
try:
bad_user = User(name="John", eye_color="blue")
except ValidationError:
pass
Let's write it to Redis
user.save()
Let's see its id. ids are UUID4 hex strings
print(user.id)
Fetch the record from Redis
user_again = User.get(id=user.id)
See the object as dictionary
print(user.asd)
Let's delete the record
user_again.delete()
Trying to find a non-existing record throws NotFound exception
from redis_models.errors import NotFound
try:
user_not_found = User.get(id=user_again.id)
except NotFound:
print("User not found!")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file redis_models-0.2.1.tar.gz.
File metadata
- Download URL: redis_models-0.2.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1676bb373927d611f2602d0b011ef9aa91ce994046e1dd342f66777024635fbf
|
|
| MD5 |
fd065ecbad2744b9b468126c36ddaa48
|
|
| BLAKE2b-256 |
829a8cb0793ab432f18da803a7ec6eb15dd12884f9bd5bde2d9066ed8943348e
|
File details
Details for the file redis_models-0.2.1-py2.py3-none-any.whl.
File metadata
- Download URL: redis_models-0.2.1-py2.py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f85fc2887e7330dca9382e2957e0074e8cd6be610ca5304cb61a838455b133f
|
|
| MD5 |
24403e2c637f6983264624d56326f537
|
|
| BLAKE2b-256 |
cfdf7a4e4685a08ce811ff313a1543777b57366125177c97c568d2bb02e0e8db
|