class Suo::Client::Redis
Constants
- OK_STR
Public Class Methods
new(key, options = {})
click to toggle source
Calls superclass method
Suo::Client::Base::new
# File lib/suo/client/redis.rb, line 6 def initialize(key, options = {}) options[:client] ||= ::Redis.new(options[:connection] || {}) super end
Public Instance Methods
clear()
click to toggle source
# File lib/suo/client/redis.rb, line 11 def clear with { |r| r.del(@key) } end
Private Instance Methods
get()
click to toggle source
# File lib/suo/client/redis.rb, line 25 def get [with { |r| r.get(@key) }, nil] end
initial_set(val = BLANK_STR)
click to toggle source
# File lib/suo/client/redis.rb, line 49 def initial_set(val = BLANK_STR) set(val, nil) nil end
set(newval, _, expire: false)
click to toggle source
# File lib/suo/client/redis.rb, line 29 def set(newval, _, expire: false) ret = with do |r| r.multi do |rr| if expire rr.setex(@key, @options[:ttl], newval) else rr.set(@key, newval) end end end ret && ret[0] == OK_STR end
synchronize() { || ... }
click to toggle source
# File lib/suo/client/redis.rb, line 43 def synchronize with { |r| r.watch(@key) { yield } } ensure with { |r| r.unwatch } end
with() { |client| ... }
click to toggle source
# File lib/suo/client/redis.rb, line 17 def with(&block) if @client.respond_to?(:with) @client.with(&block) else yield @client end end