summaryrefslogtreecommitdiff
path: root/lib/gitlab/cache/import/caching.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-26 12:07:48 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-26 12:07:48 +0000
commitef31adeb0fb9a02b2c6a4529ec4e38d7082a4b2b (patch)
treef0ee2b8bdffd7f91ad0b31388562c90825179585 /lib/gitlab/cache/import/caching.rb
parent7e019504f5ac6decde690565857238e7e59aa034 (diff)
downloadgitlab-ce-ef31adeb0fb9a02b2c6a4529ec4e38d7082a4b2b.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/cache/import/caching.rb')
-rw-r--r--lib/gitlab/cache/import/caching.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/gitlab/cache/import/caching.rb b/lib/gitlab/cache/import/caching.rb
index ead94761ae7..7f2d2858149 100644
--- a/lib/gitlab/cache/import/caching.rb
+++ b/lib/gitlab/cache/import/caching.rb
@@ -70,6 +70,21 @@ module Gitlab
value
end
+ # Increment the integer value of a key by one.
+ # Sets the value to zero if missing before incrementing
+ #
+ # 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)
+ key = cache_key_for(raw_key)
+
+ Redis::Cache.with do |redis|
+ redis.incr(key)
+ redis.expire(key, timeout)
+ end
+ end
+
# Adds a value to a set.
#
# raw_key - The key of the set to add the value to.