lib/trifle/stats/driver/redis.rb in trifle-stats-0.2.1 vs lib/trifle/stats/driver/redis.rb in trifle-stats-0.3.0
- old
+ new
@@ -6,35 +6,36 @@
module Trifle
module Stats
module Driver
class Redis
include Mixins::Packer
- attr_accessor :prefix
+ attr_accessor :client, :prefix, :separator
def initialize(client = ::Redis.current, prefix: 'trfl')
@client = client
@prefix = prefix
+ @separator = '::'
end
def inc(key:, **values)
- pkey = [@prefix, key].join('::')
+ pkey = ([prefix] + key).join(separator)
self.class.pack(hash: values).each do |k, c|
- @client.hincrby(pkey, k, c)
+ client.hincrby(pkey, k, c)
end
end
def set(key:, **values)
- pkey = [@prefix, key].join('::')
+ pkey = ([prefix] + key).join(separator)
- @client.hmset(pkey, *self.class.pack(hash: values))
+ client.hmset(pkey, *self.class.pack(hash: values))
end
def get(key:)
- pkey = [@prefix, key].join('::')
+ pkey = ([prefix] + key).join(separator)
self.class.unpack(
- hash: @client.hgetall(pkey)
+ hash: client.hgetall(pkey)
)
end
end
end
end