Sha256: 4db9159d6c7411549a5c226005543a1fa0a42342c9f386f19e2fcee5f1cea36d
Contents?: true
Size: 946 Bytes
Versions: 5
Compression:
Stored size: 946 Bytes
Contents
# frozen_string_literal: true require 'redis' require_relative '../mixins/packer' module Trifle module Stats module Driver class Redis include Mixins::Packer 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(separator) self.class.pack(hash: values).each do |k, c| client.hincrby(pkey, k, c) end end def set(key:, **values) pkey = ([prefix] + key).join(separator) client.hmset(pkey, *self.class.pack(hash: values)) end def get(key:) pkey = ([prefix] + key).join(separator) self.class.unpack( hash: client.hgetall(pkey) ) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems