-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TTL and EXPIRE functions? #17
Comments
@cohawk I agree, it would be helpful to have these functions (especially the
MyCache.set("foo", "bar", ttl: 10)
:timer.sleep(5000)
remaining_ttl =
"foo"
|> MyCache.get(return: :object)
|> Nebulex.Object.ttl()
MyCache.update("foo", nil, &(&1), ttl: 5)
Example: remaining_ttl =
"foo"
|> MyCache.update(nil, &(&1), ttl: 5, return: :object) # this acts as EXPIRE function
|> Nebulex.Object.ttl() Let me know your thoughts! |
@cabol, simple and beautiful. Passing the &(&1) function is much better than the get_and_update method that I was looking into. I think I would still create wrapper functions with documentation (at least in my code) using your above examples and explanations, since I could see myself looking back at the Expire code block and not remembering exactly what it was doing. But either way both functions are now possible. Thanks for your great work on the library! |
@cohawk thanks :) !! |
Looking through the docs and codebase I do not see a way to return a key's current TTL - only set it. Unless I am missing it somewhere? (https://redis.io/commands/ttl)
Also along those lines it would be nice to have a Redis like EXPIRE function (https://redis.io/commands/expire) to refresh a key's TTL (get and set) or return 0/false if the key does not exist (or already expired).
The text was updated successfully, but these errors were encountered: