Class: Trifle::Stats::Driver::Redis
- Inherits:
-
Object
- Object
- Trifle::Stats::Driver::Redis
- Includes:
- Mixins::Packer
- Defined in:
- lib/trifle/stats/driver/redis.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#separator ⇒ Object
Returns the value of attribute separator.
Instance Method Summary collapse
- #get(keys:) ⇒ Object
- #inc(keys:, **values) ⇒ Object
-
#initialize(client = ::Redis.current, prefix: 'trfl') ⇒ Redis
constructor
A new instance of Redis.
- #set(keys:, **values) ⇒ Object
Methods included from Mixins::Packer
Constructor Details
#initialize(client = ::Redis.current, prefix: 'trfl') ⇒ Redis
Returns a new instance of Redis.
12 13 14 15 16 |
# File 'lib/trifle/stats/driver/redis.rb', line 12 def initialize(client = ::Redis.current, prefix: 'trfl') @client = client @prefix = prefix @separator = '::' end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
10 11 12 |
# File 'lib/trifle/stats/driver/redis.rb', line 10 def client @client end |
#prefix ⇒ Object
Returns the value of attribute prefix.
10 11 12 |
# File 'lib/trifle/stats/driver/redis.rb', line 10 def prefix @prefix end |
#separator ⇒ Object
Returns the value of attribute separator.
10 11 12 |
# File 'lib/trifle/stats/driver/redis.rb', line 10 def separator @separator end |
Instance Method Details
#get(keys:) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/trifle/stats/driver/redis.rb', line 36 def get(keys:) keys.map do |key| pkey = ([prefix] + key).join(separator) self.class.unpack( hash: client.hgetall(pkey) ) end end |
#inc(keys:, **values) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/trifle/stats/driver/redis.rb', line 18 def inc(keys:, **values) keys.map do |key| pkey = ([prefix] + key).join(separator) self.class.pack(hash: values).each do |k, c| client.hincrby(pkey, k, c) end end end |
#set(keys:, **values) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/trifle/stats/driver/redis.rb', line 28 def set(keys:, **values) keys.map do |key| pkey = ([prefix] + key).join(separator) client.hmset(pkey, *self.class.pack(hash: values)) end end |