简体   繁体   English

Redis python-rom 对象过期。

[英]Redis python-rom object expiration.

I am working with flask and redis.我正在使用烧瓶和 redis。 I've decided to try the rom redis orm ( http://pythonhosted.org/rom/ ) to manage some mildly complex data structures.我决定尝试使用 rom redis orm ( http://pythonhosted.org/rom/ ) 来管理一些稍微复杂的数据结构。 I have a list of objects, lets say:我有一个对象列表,可以说:

urls = ['www.google.com', 'www.example.com', 'www.python.org']

I also have the rom model:我也有 rom 模型:

class Stored_url(rom.Model):
    url = rom.String(required=True, unique=True, suffix=True)
    salt = rom.String()
    hash = rom.String()
    created_at = rom.Float(default=time.time)

This appears to be working on my dev setup.这似乎适用于我的开发设置。 In my situation, i would like to start from scratch every day with some of the data and would like to set an expiration time for some objecta.在我的情况下,我想每天从头开始处理一些数据,并想为某些对象设置过期时间。 I've looked through the documentation at http://pythonhosted.org/rom/rom.html# , but have not found a reference to expiration except in request caching.我已经浏览了http://pythonhosted.org/rom/rom.html# 上的文档,但除了请求缓存之外,没有找到对过期的引用。 Is there a way to allow rom objects to expire?有没有办法让 rom 对象过期?

Rom does not offer a built-in method automatic to automatically expire data. Rom 不提供自动使数据自动过期的内置方法。 This is on purpose.这是故意的。 I have explained the reasons why on 3 previous occasions:我已经解释了前 3 次的原因:

TL;DR; TL; 博士; Redis does not offer the internal mechanisms necessary to make this automatic (triggers). Redis 不提供使此自动化(触发器)所需的内部机制。 I provide 2 workarounds in the pull request linked above.我在上面链接的拉取请求中提供了 2 个解决方法。

From rom documentation, it's better to create a new expire_at float column with index=True, the column can store when the entity is to expire.从 rom 文档中,最好创建一个 index=True 的新 expire_at 浮点列,该列可以存储实体何时到期。 Then to expire the data, you can use: Model.query.filter(expire_at=(0, time.time())).limit(10) to (for example) get up to the 10 oldest entites that need to be expired.然后要使数据过期,您可以使用: Model.query.filter(expire_at=(0, time.time())).limit(10) 到(例如)最多需要过期的 10 个最旧的实体.

https://josiahcarlson.github.io/rom/rom.html#expiring-models-ttls https://josiahcarlson.github.io/rom/rom.html#expiring-models-ttls

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM