diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /lib/gitlab/cache | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
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. |