Module: Counterman::HashOperations

Extended by:
Forwardable
Included in:
TimeSpan
Defined in:
lib/counterman/hash_operations.rb

Instance Method Summary collapse

Instance Method Details

#all_countsObject



19
20
21
22
23
24
25
# File 'lib/counterman/hash_operations.rb', line 19

def all_counts
  counts = redis.hgetall(key)
  counts.inject({}) do |hash, (k,v)|
    hash[k.to_i] = v.to_i
    hash
  end
end

#count(id) ⇒ Object



7
8
9
# File 'lib/counterman/hash_operations.rb', line 7

def count(id)
  safe { redis.hget(key, id).to_i }
end

#count_all(ids) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/counterman/hash_operations.rb', line 11

def count_all(ids)
  redis.pipelined do
    ids.each do |id|
      redis.hget(key, id)
    end
  end.map(&:to_i)
end