Class: FMCache::Client
- Inherits:
-
Object
- Object
- FMCache::Client
- Defined in:
- lib/fmcache/client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#notifier ⇒ Object
readonly
Returns the value of attribute notifier.
Instance Method Summary collapse
- #del(keys:) ⇒ Boolean
- #get(keys:, fields:) ⇒ { String => { String => String } }
- #hdel(keys:, fields:) ⇒ Boolean
-
#initialize(client, notifier = nil) ⇒ Client
constructor
A new instance of Client.
- #set(values:, ttl:) ⇒ Boolean
Constructor Details
#initialize(client, notifier = nil) ⇒ Client
Returns a new instance of Client.
5 6 7 8 |
# File 'lib/fmcache/client.rb', line 5 def initialize(client, notifier = nil) @client = client @notifier = notifier end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/fmcache/client.rb', line 10 def client @client end |
#notifier ⇒ Object (readonly)
Returns the value of attribute notifier.
10 11 12 |
# File 'lib/fmcache/client.rb', line 10 def notifier @notifier end |
Instance Method Details
#del(keys:) ⇒ Boolean
47 48 49 50 51 52 53 54 55 |
# File 'lib/fmcache/client.rb', line 47 def del(keys:) if keys.size > 0 client.del(*keys) end true rescue Redis::BaseConnectionError => e notify(e) false end |
#get(keys:, fields:) ⇒ { String => { String => String } }
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fmcache/client.rb', line 31 def get(keys:, fields:) return {} if keys.size == 0 values = client.pipelined do keys.each do |key| client.mapped_hmget(key, *fields) end end keys.zip(values).to_h rescue Redis::BaseConnectionError => e notify(e) keys.map { |k| [k, fields.map { |f| [f, nil] }.to_h] }.to_h end |
#hdel(keys:, fields:) ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fmcache/client.rb', line 60 def hdel(keys:, fields:) client.pipelined do keys.each do |key| fields.each do |field| client.hdel(key, field) end end end true rescue Redis::BaseConnectionError => e notify(e) false end |
#set(values:, ttl:) ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fmcache/client.rb', line 14 def set(values:, ttl:) client.pipelined do values.each do |h_key, h_values| client.mapped_hmset(h_key, h_values) client.expire(h_key, ttl) end end true rescue Redis::BaseConnectionError => e notify(e) false end |