class ActionHandle::Adapters::RedisPool

Constants

CurrentRedisWapper

Public Class Methods

new(pool = nil) click to toggle source
# File lib/action_handle/adapters/redis_pool.rb, line 15
def initialize(pool = nil)
  @pool = pool || CurrentRedisWapper.new
end

Public Instance Methods

claim(key, value, ttl) click to toggle source
# File lib/action_handle/adapters/redis_pool.rb, line 53
def claim(key, value, ttl)
  perform_with_expectation('OK') do
    @pool.with do |client|
      client.set(key, value, ex: ttl)
    end
  end
end
create(key, value, ttl) click to toggle source
# File lib/action_handle/adapters/redis_pool.rb, line 19
def create(key, value, ttl)
  perform_with_expectation(true) do
    @pool.with do |client|
      client.set(key, value, ex: ttl, nx: true)
    end
  end
end
current?(key, value) click to toggle source
# File lib/action_handle/adapters/redis_pool.rb, line 41
def current?(key, value)
  perform_with_expectation(value.to_s) do
    @pool.with { |client| client.get(key) }
  end
end
expire(key) click to toggle source
# File lib/action_handle/adapters/redis_pool.rb, line 61
def expire(key)
  perform_with_expectation(1) do
    @pool.with { |client| client.del(key) }
  end
end
renew(key, value, ttl) click to toggle source
# File lib/action_handle/adapters/redis_pool.rb, line 27
def renew(key, value, ttl)
  perform_with_expectation(true) do
    @pool.with do |client|
      client.expire(key, ttl) if current?(key, value)
    end
  end
end
taken?(key) click to toggle source
# File lib/action_handle/adapters/redis_pool.rb, line 35
def taken?(key)
  perform_with_expectation(true) do
    @pool.with { |client| client.exists?(key) }
  end
end
value(key) click to toggle source
# File lib/action_handle/adapters/redis_pool.rb, line 47
def value(key)
  safely_perform do
    @pool.with { |client| client.get(key) }
  end
end