diff options
Diffstat (limited to 'lib/gitlab/cache/import/caching.rb')
-rw-r--r-- | lib/gitlab/cache/import/caching.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/gitlab/cache/import/caching.rb b/lib/gitlab/cache/import/caching.rb index 4cbc0231bce..89c85cb50be 100644 --- a/lib/gitlab/cache/import/caching.rb +++ b/lib/gitlab/cache/import/caching.rb @@ -57,7 +57,7 @@ module Gitlab # Sets a cache key to the given value. # - # key - The cache key to write. + # raw_key - The cache key to write. # value - The value to set. # timeout - The time after which the cache key should expire. def self.write(raw_key, value, timeout: TIMEOUT) @@ -73,7 +73,7 @@ module Gitlab # Increment the integer value of a key by one. # Sets the value to zero if missing before incrementing # - # key - The cache key to increment. + # raw_key - The cache key to increment. # timeout - The time after which the cache key should expire. # @return - the incremented value def self.increment(raw_key, timeout: TIMEOUT) @@ -85,6 +85,22 @@ module Gitlab end end + # Increment the integer value of a key by the given value. + # Sets the value to zero if missing before incrementing + # + # raw_key - The cache key to increment. + # value - The value to increment the key + # timeout - The time after which the cache key should expire. + # @return - the incremented value + def self.increment_by(raw_key, value, timeout: TIMEOUT) + key = cache_key_for(raw_key) + + Redis::Cache.with do |redis| + redis.incrby(key, value) + redis.expire(key, timeout) + end + end + # Adds a value to a set. # # raw_key - The key of the set to add the value to. |