Module: Gitlab::UsageDataCounters::RedisHashCounter
- Defined in:
- lib/gitlab/usage_data_counters/redis_hash_counter.rb
Instance Method Summary collapse
- #get_hash(redis_counter_key) ⇒ Object
- #hash_increment(redis_counter_key, hash_key, expiry: nil) ⇒ Object
Instance Method Details
#get_hash(redis_counter_key) ⇒ Object
20 21 22 |
# File 'lib/gitlab/usage_data_counters/redis_hash_counter.rb', line 20 def get_hash(redis_counter_key) Gitlab::Redis::SharedState.with { |redis| redis.hgetall(redis_counter_key).transform_values(&:to_i) } end |
#hash_increment(redis_counter_key, hash_key, expiry: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/gitlab/usage_data_counters/redis_hash_counter.rb', line 9 def hash_increment(redis_counter_key, hash_key, expiry: nil) Gitlab::Redis::SharedState.with do |redis| redis.hincrby(redis_counter_key, hash_key, 1) unless expiry.nil? existing_expiry = redis.ttl(redis_counter_key) > 0 redis.expire(redis_counter_key, expiry) unless existing_expiry end end end |