Class: Gitlab::Experiment::Cache::RedisHashStore

Inherits:
ActiveSupport::Cache::Store
  • Object
show all
Defined in:
lib/gitlab/experiment/cache/redis_hash_store.rb

Instance Method Summary collapse

Instance Method Details

#clear(key:) ⇒ Object

Clears the entire cache for a given experiment. Be careful with this since it would reset all resolved variants for the entire experiment.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/experiment/cache/redis_hash_store.rb', line 23

def clear(key:)
  key = hkey(key)[0] # extract only the first part of the key
  pool do |redis|
    case redis.type(key)
    when 'hash', 'none'
      redis.del(key) # delete the primary experiment key
      redis.del("#{key}_attrs") # delete the experiment attributes key
    else raise ArgumentError, 'invalid call to clear a non-hash cache key'
    end
  end
end

#increment(key, amount = 1) ⇒ Object



35
36
37
# File 'lib/gitlab/experiment/cache/redis_hash_store.rb', line 35

def increment(key, amount = 1)
  pool { |redis| redis.hincrby(*hkey(key), amount) }
end