Redis: possible to expire an element in an array or sorted set?

后端 未结 3 577
面向向阳花
面向向阳花 2020-12-02 07:19

Is it currently only possible to expire an entire key/value pair? What if I want to add values to a List type structure and have them get auto removed 1 hour after insertion

3条回答
  •  余生分开走
    2020-12-02 07:51

    I came upon a different method of handling this, don't know if it's helpful to any of you,but here goes:

    The hash and the sorted set are linked by a guid.

    1. I have a hash that is set to expire in 'x' seconds
    2. I have a sorted set that is used for ranged queries
    3. The data for both is added in a transaction, so if one fails, they both fail.
    4. Upon a ranged query, use 'EXISTS' to see if the hashed value exists as the results are iterated over
    5. If it does not exist, it has expired, so delete the item from the sorted set

提交回复
热议问题