Git Product home page Git Product logo

Comments (3)

coleifer avatar coleifer commented on September 23, 2024

Walrus extends the redis-py client so all the redis methods are available: https://redis-py.readthedocs.io/en/stable/commands.html#redis.commands.core.CoreCommands.expire

from walrus.

sridhar562345 avatar sridhar562345 commented on September 23, 2024

@coleifer
I am trying to expire the key as below, but getting the object has no attribute expire error

from walrus import Model, TextField, DateTimeField, Database

db = Database(host="host", port="port")


class Hello(Model):
    __database__ = db

    name = TextField(primary_key=True)
    ...
    
user_drop = Hello.get(Hello.name == "some_name")
user_drop.expire(10)

Am I missing something or is there another way of handling it?

from walrus.

coleifer avatar coleifer commented on September 23, 2024

Models are not a good fit for simple expiry since they may contain a number of values stored in indexes, but if you are not using any indexes you can:

user_drop = Hello.get(...)
user_hash = user_drop.to_hash()  # Get corresponding hash.
user_hash.expire(10)  # Will expire the underlying hash, but not the data in the indexes.

To see what is necessary to remove from indexes, see the Model.delete() code in the models.py file. In short, models are composite data-structures are will not play well with simple expiration logic.

from walrus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.