mirror of
https://github.com/dkam/suo.git
synced 2025-01-29 07:42:43 +00:00
Support connection pooled Redis
This commit is contained in:
@@ -9,21 +9,31 @@ module Suo
|
|||||||
end
|
end
|
||||||
|
|
||||||
def clear
|
def clear
|
||||||
@client.del(@key)
|
with { |r| r.del(@key) }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def with(&block)
|
||||||
|
if @client.respond_to?(:with)
|
||||||
|
@client.with(&block)
|
||||||
|
else
|
||||||
|
yield @client
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get
|
def get
|
||||||
[@client.get(@key), nil]
|
[with { |r| r.get(@key) }, nil]
|
||||||
end
|
end
|
||||||
|
|
||||||
def set(newval, _, expire: false)
|
def set(newval, _, expire: false)
|
||||||
ret = @client.multi do |multi|
|
ret = with do |r|
|
||||||
|
r.multi do |rr|
|
||||||
if expire
|
if expire
|
||||||
multi.setex(@key, @options[:ttl], newval)
|
rr.setex(@key, @options[:ttl], newval)
|
||||||
else
|
else
|
||||||
multi.set(@key, newval)
|
rr.set(@key, newval)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -31,11 +41,9 @@ module Suo
|
|||||||
end
|
end
|
||||||
|
|
||||||
def synchronize
|
def synchronize
|
||||||
@client.watch(@key) do
|
with { |r| r.watch(@key) { yield } }
|
||||||
yield
|
|
||||||
end
|
|
||||||
ensure
|
ensure
|
||||||
@client.unwatch
|
with { |r| r.unwatch }
|
||||||
end
|
end
|
||||||
|
|
||||||
def initial_set(val = BLANK_STR)
|
def initial_set(val = BLANK_STR)
|
||||||
|
|||||||
Reference in New Issue
Block a user