Class: Trifle::Ruby::Driver::Redis

Inherits:
Object
  • Object
show all
Includes:
Mixins::Packer
Defined in:
lib/trifle/ruby/driver/redis.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Packer

included

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

#prefixObject

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