Adds expire and test.

This commit is contained in:
Simon Prickett 2022-03-29 22:15:05 +01:00
parent f024b39c16
commit b42e63606a
2 changed files with 27 additions and 0 deletions

View file

@ -1130,6 +1130,15 @@ class RedisModel(BaseModel, abc.ABC, metaclass=ModelMeta):
async def save(self, pipeline: Optional[Pipeline] = None) -> "RedisModel":
raise NotImplementedError
async def expire(self, num_seconds: int, pipeline: Optional[Pipeline] = None):
if pipeline is None:
db = self.db()
else:
db = pipeline
# TODO: Wrap any Redis response errors in a custom exception?
await db.expire(self.make_primary_key(self.pk), num_seconds)
@validator("pk", always=True, allow_reuse=True)
def validate_pk(cls, v):
if not v: