Sha256: 8abcfb3d3a20759b53c722657bd1009c2cf55402e775d4687017cb958b30e4bc
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
# frozen_string_literal: true require 'redis' require 'connection_pool' module ActionHandle module Adapters class RedisPool < Base CurrentRedisWapper = Class.new do def with yield(Redis.current) end end def initialize(pool = nil) @pool = pool || CurrentRedisWapper.new end def taken?(key) perform_with_expectation(true) do @pool.with { |client| client.exist(key) } end end def current?(key, value) perform_with_expectation(value.to_s) do @pool.with { |client| client.get(key) } end end def info(key) safely_perform do @pool.with { |client| client.get(key) } end end def claim(key, value, ttl) perform_with_expectation('OK') do @pool.with do |client| client.set(key, value, ex: ttl) end end end def expire(key) perform_with_expectation(1) do @pool.with { |client| client.del(key) } end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
action-handle-0.0.3 | lib/action_handle/adapters/redis_pool.rb |