summaryrefslogtreecommitdiff
path: root/lib/gitlab/cache/import/caching.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/cache/import/caching.rb')
-rw-r--r--lib/gitlab/cache/import/caching.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/gitlab/cache/import/caching.rb b/lib/gitlab/cache/import/caching.rb
index 86441973941..4cbc0231bce 100644
--- a/lib/gitlab/cache/import/caching.rb
+++ b/lib/gitlab/cache/import/caching.rb
@@ -173,6 +173,34 @@ module Gitlab
val ? true : false
end
+ # Adds a value to a hash.
+ #
+ # raw_key - The key of the hash to add to.
+ # field - The field to add to the hash.
+ # value - The field value to add to the hash.
+ # timeout - The new timeout of the key.
+ def self.hash_add(raw_key, field, value, timeout: TIMEOUT)
+ key = cache_key_for(raw_key)
+
+ Redis::Cache.with do |redis|
+ redis.multi do |m|
+ m.hset(key, field, value)
+ m.expire(key, timeout)
+ end
+ end
+ end
+
+ # Returns the values of the given hash.
+ #
+ # raw_key - The key of the set to check.
+ def self.values_from_hash(raw_key)
+ key = cache_key_for(raw_key)
+
+ Redis::Cache.with do |redis|
+ redis.hgetall(key)
+ end
+ end
+
def self.cache_key_for(raw_key)
"#{Redis::Cache::CACHE_NAMESPACE}:#{raw_key}"
end