Module: Legion::Cache::Redis
Instance Method Summary
collapse
Methods included from Pool
#available, #close, #connected?, #pool_size, #restart, #size, #timeout
Instance Method Details
#client(pool_size: 20, timeout: 5) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# 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) ⇒ Object
34
35
36
|
# File 'lib/legion/cache/redis.rb', line 34
def delete(key)
client.with { |conn| conn.del(key) == 1 }
end
|
#flush ⇒ Object
38
39
40
|
# File 'lib/legion/cache/redis.rb', line 38
def flush
client.with { |conn| conn.flushdb == 'OK' }
end
|
#get(key) ⇒ Object
Also known as:
fetch
23
24
25
|
# File 'lib/legion/cache/redis.rb', line 23
def get(key)
client.with { |conn| conn.get(key) }
end
|
#set(key, value, ttl: nil) ⇒ Object
28
29
30
31
32
|
# 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
|