Class: BellyWash::Driver::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/belly_wash/driver/redis.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client = ::Redis.current, prefix: 'bw') ⇒ Redis

Returns a new instance of Redis.



10
11
12
13
# File 'lib/belly_wash/driver/redis.rb', line 10

def initialize(client = ::Redis.current, prefix: 'bw')
  @client = client
  @prefix = prefix
end

Instance Attribute Details

#prefixObject

Returns the value of attribute prefix.



8
9
10
# File 'lib/belly_wash/driver/redis.rb', line 8

def prefix
  @prefix
end

Instance Method Details

#get(key:) ⇒ Object



22
23
24
25
# File 'lib/belly_wash/driver/redis.rb', line 22

def get(key:)
  pkey = [@prefix, key].join('::')
  @client.hgetall(pkey)
end

#inc(key:, **values) ⇒ Object



15
16
17
18
19
20
# File 'lib/belly_wash/driver/redis.rb', line 15

def inc(key:, **values)
  pkey = [@prefix, key].join('::')
  values.each do |k, c|
    @client.hincrby(pkey, k, c)
  end
end