@ -24,8 +24,6 @@ from typing import (
no_type_check ,
no_type_check ,
)
)
import aioredis
from aioredis . client import Pipeline
from pydantic import BaseModel , validator
from pydantic import BaseModel , validator
from pydantic . fields import FieldInfo as PydanticFieldInfo
from pydantic . fields import FieldInfo as PydanticFieldInfo
from pydantic . fields import ModelField , Undefined , UndefinedType
from pydantic . fields import ModelField , Undefined , UndefinedType
@ -35,9 +33,10 @@ from pydantic.utils import Representation
from typing_extensions import Protocol , get_args , get_origin
from typing_extensions import Protocol , get_args , get_origin
from ulid import ULID
from ulid import ULID
from . . import redis
from . . checks import has_redis_json , has_redisearch
from . . checks import has_redis_json , has_redisearch
from . . connections import get_redis_connection
from . . connections import get_redis_connection
from . . u nasync_u til import ASYNC_MODE
from . . u til import ASYNC_MODE
from . encoders import jsonable_encoder
from . encoders import jsonable_encoder
from . render_tree import render_tree
from . render_tree import render_tree
from . token_escaper import TokenEscaper
from . token_escaper import TokenEscaper
@ -978,7 +977,7 @@ class BaseMeta(Protocol):
global_key_prefix : str
global_key_prefix : str
model_key_prefix : str
model_key_prefix : str
primary_key_pattern : str
primary_key_pattern : str
database : aio redis. Redis
database : redis. Redis
primary_key : PrimaryKey
primary_key : PrimaryKey
primary_key_creator_cls : Type [ PrimaryKeyCreator ]
primary_key_creator_cls : Type [ PrimaryKeyCreator ]
index_name : str
index_name : str
@ -997,7 +996,7 @@ class DefaultMeta:
global_key_prefix : Optional [ str ] = None
global_key_prefix : Optional [ str ] = None
model_key_prefix : Optional [ str ] = None
model_key_prefix : Optional [ str ] = None
primary_key_pattern : Optional [ str ] = None
primary_key_pattern : Optional [ str ] = None
database : Optional [ aio redis. Redis ] = None
database : Optional [ redis. Redis ] = None
primary_key : Optional [ PrimaryKey ] = None
primary_key : Optional [ PrimaryKey ] = None
primary_key_creator_cls : Optional [ Type [ PrimaryKeyCreator ] ] = None
primary_key_creator_cls : Optional [ Type [ PrimaryKeyCreator ] ] = None
index_name : Optional [ str ] = None
index_name : Optional [ str ] = None
@ -1130,10 +1129,14 @@ class RedisModel(BaseModel, abc.ABC, metaclass=ModelMeta):
""" Update this model instance with the specified key-value pairs. """
""" Update this model instance with the specified key-value pairs. """
raise NotImplementedError
raise NotImplementedError
async def save ( self , pipeline : Optional [ Pipeline ] = None ) - > " RedisModel " :
async def save (
self , pipeline : Optional [ redis . client . Pipeline ] = None
) - > " RedisModel " :
raise NotImplementedError
raise NotImplementedError
async def expire ( self , num_seconds : int , pipeline : Optional [ Pipeline ] = None ) :
async def expire (
self , num_seconds : int , pipeline : Optional [ redis . client . Pipeline ] = None
) :
if pipeline is None :
if pipeline is None :
db = self . db ( )
db = self . db ( )
else :
else :
@ -1226,7 +1229,7 @@ class RedisModel(BaseModel, abc.ABC, metaclass=ModelMeta):
async def add (
async def add (
cls ,
cls ,
models : Sequence [ " RedisModel " ] ,
models : Sequence [ " RedisModel " ] ,
pipeline : Optional [ Pipeline] = None ,
pipeline : Optional [ redis. client . Pipeline] = None ,
pipeline_verifier : Callable [ . . . , Any ] = verify_pipeline_response ,
pipeline_verifier : Callable [ . . . , Any ] = verify_pipeline_response ,
) - > Sequence [ " RedisModel " ] :
) - > Sequence [ " RedisModel " ] :
if pipeline is None :
if pipeline is None :
@ -1286,7 +1289,9 @@ class HashModel(RedisModel, abc.ABC):
f " HashModels cannot index dataclass fields. Field: { name } "
f " HashModels cannot index dataclass fields. Field: { name } "
)
)
async def save ( self , pipeline : Optional [ Pipeline ] = None ) - > " HashModel " :
async def save (
self , pipeline : Optional [ redis . client . Pipeline ] = None
) - > " HashModel " :
self . check ( )
self . check ( )
if pipeline is None :
if pipeline is None :
db = self . db ( )
db = self . db ( )
@ -1458,7 +1463,9 @@ class JsonModel(RedisModel, abc.ABC):
)
)
super ( ) . __init__ ( * args , * * kwargs )
super ( ) . __init__ ( * args , * * kwargs )
async def save ( self , pipeline : Optional [ Pipeline ] = None ) - > " JsonModel " :
async def save (
self , pipeline : Optional [ redis . client . Pipeline ] = None
) - > " JsonModel " :
self . check ( )
self . check ( )
if pipeline is None :
if pipeline is None :
db = self . db ( )
db = self . db ( )