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