redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.11k stars 111 forks source link

[Feature Request] Allow default expiry time for a model #529

Open XChikuX opened 1 year ago

XChikuX commented 1 year ago

Currently we are able to set an expiry after saving the model.

class Like(HashModel):
    user_id: str
    liked_user_id: str

    @root_validator()
    def assign_pk(cls, values):
        values["pk"] = f"{values['user_id']}:{values['liked_user_id']}"
        return values

    class Meta:
        database = redis_conn

like1 = Like(user_id="1", liked_user_id="2")
like1.expire(120)

I'd like all my 'Like' instances to have a default expiry time, instead of defining it each time and updating redis in the background.

javitab commented 11 months ago

I would also like to see this as a feature under the Meta class, but I think you could honestly do this just as easily by overriding the built-in save method.