diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-22 21:08:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-22 21:08:29 +0300 |
commit | d81dc2a54e28f4e6d7515545dfe0dc19d9e57816 (patch) | |
tree | b80756d280382e93b209fd4fe5193c075ee4d292 /lib/gitlab/cache | |
parent | 684f0a68d56bd3aab8cb7a7e790be847feb22f71 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/cache')
-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. |