Redis scripts do not expire keys atomically
ably.com
ably.com
Maybe you could store the related keys in a hash or something?
I'm also guilty of trying to use features in redis in ways they weren't really designed for - it's such a fantastic bit of technology that a lot of the time you can still get away with it but it's not redis's fault when it doesn't work!
There is also a "passive" key expiry where any read to a key will check the expiry time and delete the key if the current time is larger than the expiry time.
Why are you assuming that? And if true, why do you think that assumption will hold in the future????? Redis could always tweak or change the behavior.
One hack I can think of is, accessing the keys. If the key is expired, then Redis won't provide it and you could know it is expired.
Another way is to club all of the relative keys in a hash [1]
[0] - https://redis.io/commands/expire#how-redis-expires-keys
sorry should have been more clear
Using a Key-Value DB to store relational data eh - that never leads to problems.
Their solution isn't any better because the API does not guarantee a particular order or atomicity of key expiration - so great that it works for you now[1], but next version may change the behavior.
[1] Does it work though? Are you really really sure?
Sorry it wasent that clear that part of our fix was such that it no longer matters if all keys exist or none - we reordered the expires such that the invariants still hold even if all the keys dont still exist My understanding of expiry is - its not guaranteed when keys are expired if they are not accessed - but if a looked up keys TTL is hit it will not be returned - which is all we cared about
It's been a while since I had to deal with this kind of problem though, so please tell me if things are different now.
I never got the impression that Redis gave guarantees on when expired keys were deleted, just that they would be eventually.
If the issue is that you want a consistent all or nothing, why not just use a single key to make that determination?
- If the keys are strings, just use a single hashmap and you're done.
- If the keys have different types, then you need a Redis module that implements something like `MPEXPIREAT time key1 key2 ...` and then you need to either be able to handle the case where you successfully retrieve key1 but not key2 (because they expired half-way through) or you use a lua script to execute the multi-key access atomically. That said, without the lua script the whole point of having the keys expire at the same time makes less sense, IMO.
If you happen to have a question that ends up on the wrong side of that trade-off between documentation's completeness and accessibility, you will have to descend into the depths that lie beneath. I believe the redis documentation actually strikes a rather OK balance in that regard.
The edge cases and quirky impl detail questions are what src is for.
Literally the most important thing you can document.