Expiring objects in python-stdnet?
One of the main reasons for me to use Redis is as a cache; so it is very important that I can insert keys with specify expires (using Redis; not my own custom expires_in member).
How do I expire keys in python-stdnet?
In my exploring, I can't find such feature. I think Stdnet doesn't support it. Because, Stdnet intends to support multi-backend which may not support expiring entry.
For now, manual deleting (by creation/update datetime) using model is only way. I think this is only way for consistency.
Many NoSQL stores support this feature, for those that don't you can handle it manually (e.g.: push a timestamp on each expirable record, on get requests check if it's still valid before returning to requester, if expired delete from db)
stdnet is a data mapper, one instance of a model can have several keys associated with it. For example, in redis an object has a key for the hash, a key for every index (either sets or zset) and few others for internal use.
In this respect, it doesn't make lots of sense talking about expiring keys in stdnet, expiring objects could be the equivalent. Such feature is not available, if you need to expire them you can do it programmatically by deleting them.
If you are using redis as a cache, why do you need the object data mapping of stdnet? Do you want to expire keys or objects? Can you share your use case?
I thought also the feature before. A case is making an ephemeral odm object by TTL. In redis, automatic expiring redis object is supported natively, and it prevents code bugs which related to deleting. But in stdnet, such object may break system data structure.
By writing above, I got an idea. Let me explain.
- introduce a field for TTL, called "_ttl" here.
- if a odm object specified as ephemeral object and related backend supports it, set correspond TTL value for the field in Hash.
- in retrieving the object in Lua script, returns none if the TTL is over.
- also delete the object in stdnet.
How about this? We can do the step 1, but step 2-4 needs stdnet support.
Sounds interesting but I don't need this feature and I don't have time at the moment. Happy to assist if anyone decides to implement it.
OK, but which branch is better for development? Branch dev seems broken by ci..
I would create a new branch from master
@lsbardel I've made an issue #81 as another topic