Simple redis storage for pydantic objects with an interface of the MutableMapping.
Project description
redantic
Simple redis storage for pydantic objects with an interface of the MutableMapping.
Examples
from redantic import RedisDict
from pydantic import BaseModel
from redis import Redis
class Car(BaseModel):
price: float
model: str
CarId = int
client = Redis()
d = RedisDict[CarId, Car](client=client, name='car_collection', key_type=CarId, value_type=Car)
d[1] = Car(price=100.5, model='a')
d[2] = Car(price=200, model='b')
print(len(d))
for i in d:
print(d[i])
You can also use pydantic object as a key.
class CarId(BaseModel):
id: int
type: str
d[CarId(id=1, type='some_type')] = Car(price=100.5, model='a')
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
redantic-0.1.1.tar.gz
(3.0 kB
view hashes)