module Legion::Cache::Redis

Public Instance Methods

client(pool_size: 20, timeout: 5, **) click to toggle source
# File lib/legion/cache/redis.rb, line 10
def client(pool_size: 20, timeout: 5, **)
  return @client unless @client.nil?

  @pool_size = pool_size
  @timeout = timeout

  @client = ConnectionPool.new(size: pool_size, timeout: timeout) do
    ::Redis.new
  end
  @connected = true
  @client
end
delete(key) click to toggle source
# File lib/legion/cache/redis.rb, line 34
def delete(key)
  client.with { |conn| conn.del(key) == 1 }
end
fetch(key)
Alias for: get
flush() click to toggle source
# File lib/legion/cache/redis.rb, line 38
def flush
  client.with { |conn| conn.flushdb == 'OK' }
end
get(key) click to toggle source
# File lib/legion/cache/redis.rb, line 23
def get(key)
  client.with { |conn| conn.get(key) }
end
Also aliased as: fetch
set(key, value, ttl: nil) click to toggle source
# File lib/legion/cache/redis.rb, line 28
def set(key, value, ttl: nil)
  args = {}
  args[:ex] = ttl unless ttl.nil?
  client.with { |conn| conn.set(key, value, **args) == 'OK' }
end