-
Notifications
You must be signed in to change notification settings - Fork 78
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
Cannot set expiration time for lists #129
Comments
https://github.com/rails/kredis/blob/main/lib/kredis/types.rb#L64-L66 def list(key, default: nil, typed: :string, config: :shared, after_change: nil)
type_from(List, config, key, after_change: after_change, default: default, typed: typed)
end It appears that some kredis types do not support |
@nzwsch Yes, I have to do a little trick to expire work:
module Kredis::Types
def list(key, typed: :string, config: :shared, after_change: nil, expires_in: nil)
type_from(List, config, key, after_change: after_change, typed: typed, expires_in: expires_in)
end
def unique_list(key, typed: :string, limit: nil, config: :shared, after_change: nil, expires_in: nil)
type_from(UniqueList, config, key, after_change: after_change, typed: typed, limit: limit, expires_in: expires_in)
end
end
class Kredis::Types::List < Kredis::Types::Proxying
proxying :lrange, :lrem, :lpush, :ltrim, :rpush, :exists?, :del, :expire
attr_accessor :typed, :expires_in
def prepend(*elements)
return unless elements.flatten.any?
l = lpush types_to_strings(elements, typed)
set_expire
l
end
def append(*elements)
return unless elements.flatten.any?
r = rpush types_to_strings(elements, typed)
set_expire
r
end
alias << append
private
attr_accessor :expire_at
def set_expire
return unless expires_in
if expired?
@expire_at = expires_in.from_now
expire expires_in
end
end
def expired?
!expire_at || expire_at.past?
end
end I have to do the same with hash type too. Would be nice to have this behavior in the Kredis itself |
Pull request welcome 🤗 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm creating a list of items with an expiration time, but, I'm having the following error:
The text was updated successfully, but these errors were encountered: