Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/cache/import/caching.rb')
-rw-r--r--lib/gitlab/cache/import/caching.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/gitlab/cache/import/caching.rb b/lib/gitlab/cache/import/caching.rb
index f3251d47e7a..bc1671ff650 100644
--- a/lib/gitlab/cache/import/caching.rb
+++ b/lib/gitlab/cache/import/caching.rb
@@ -239,6 +239,25 @@ module Gitlab
end
end
+ # Increments value of a field in a hash
+ #
+ # raw_key - The key of the hash to add to.
+ # field - The field to increment.
+ # value - The field value to add to the hash.
+ # timeout - The new timeout of the key.
+ def self.hash_increment(raw_key, field, value, timeout: TIMEOUT)
+ return if value.to_i <= 0
+
+ key = cache_key_for(raw_key)
+
+ with_redis do |redis|
+ redis.multi do |m|
+ m.hincrby(key, field, value.to_i)
+ m.expire(key, timeout)
+ end
+ end
+ end
+
# Adds a value to a list.
#
# raw_key - The key of the list to add to.