class Gitlab::Experiment::Cache::RedisHashStore
Public Instance Methods
clear(key:)
click to toggle source
Clears the entire cache for a given experiment. Be careful with this since it would reset all resolved variants for the entire experiment.
# 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)
click to toggle source
# File lib/gitlab/experiment/cache/redis_hash_store.rb, line 35 def increment(key, amount = 1) pool { |redis| redis.hincrby(*hkey(key), amount) } end
Private Instance Methods
delete_entry(key, **options)
click to toggle source
# File lib/gitlab/experiment/cache/redis_hash_store.rb, line 62 def delete_entry(key, **options) pool { |redis| redis.hdel(*hkey(key)) } end
hkey(key)
click to toggle source
# File lib/gitlab/experiment/cache/redis_hash_store.rb, line 47 def hkey(key) key.to_s.split(':') # this assumes the default strategy in gitlab-experiment end
pool(&block)
click to toggle source
# File lib/gitlab/experiment/cache/redis_hash_store.rb, line 41 def pool(&block) raise ArgumentError, 'missing block' unless block.present? @options[:pool].call(&block) end
read_entry(key, **options)
click to toggle source
# File lib/gitlab/experiment/cache/redis_hash_store.rb, line 51 def read_entry(key, **options) value = pool { |redis| redis.hget(*hkey(key)) } value.nil? ? nil : ActiveSupport::Cache::Entry.new(value) end
write_entry(key, entry, **options)
click to toggle source
# File lib/gitlab/experiment/cache/redis_hash_store.rb, line 56 def write_entry(key, entry, **options) return false if entry.value.blank? # don't cache any empty values pool { |redis| redis.hset(*hkey(key), entry.value) } end