You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 21, 2025. It is now read-only.
* feat: auto_sync and auto_save
This is a new feature that adds _auto_save and some accompanying tweaks
to _auto_sync. Additionally, it adds an update() context manager to make
it simple to do a bunch of updates to a model and sync to redis at the
end.
* ci: restrict characters
* ci: make sure ints are unique
* ci: remove hypothesis
By default, a pydantic-aioredis model is only saved to Redis when its .save() method is called or when it is inserted(). This is to prevent unnecessary writes to Redis.
5
+
6
+
pydantic-aioredis has two options you can tweak for automatic saving:
7
+
* _auto_save: Used to determine if a model is saved to redis on instantiate
8
+
* _auto_sync: Used to determine if a change to a model is saved on setattr
9
+
10
+
These options can be set on a model or on a per instance basis.
11
+
12
+
.. code-block::
13
+
14
+
import asyncio
15
+
from pydantic_aioredis import RedisConfig, Model, Store
16
+
17
+
class Book(Model):
18
+
_primary_key_field: str = 'title'
19
+
title: str
20
+
author: str
21
+
22
+
_auto_save: bool = True
23
+
_auto_sync: bool = True
24
+
25
+
26
+
class Movie(Model):
27
+
_primary_key_field: str = 'title'
28
+
title: str
29
+
director: str
30
+
31
+
_auto_sync: bool = True
32
+
33
+
34
+
35
+
# Create the store and register your models
36
+
store = Store(name='some_name', redis_config=RedisConfig(db=5, host='localhost', port=6379), life_span_in_seconds=3600)
0 commit comments