diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /lib/gitlab/repository_set_cache.rb | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'lib/gitlab/repository_set_cache.rb')
-rw-r--r-- | lib/gitlab/repository_set_cache.rb | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/lib/gitlab/repository_set_cache.rb b/lib/gitlab/repository_set_cache.rb index 69c1688767c..f73ac628bce 100644 --- a/lib/gitlab/repository_set_cache.rb +++ b/lib/gitlab/repository_set_cache.rb @@ -36,10 +36,32 @@ module Gitlab end def fetch(key, &block) - if exist?(key) - read(key) - else - write(key, yield) + full_key = cache_key(key) + + smembers, exists = with do |redis| + redis.multi do + redis.smembers(full_key) + redis.exists(full_key) + end + end + + return smembers if exists + + write(key, yield) + end + + # Searches the cache set using SSCAN with the MATCH option. The MATCH + # parameter is the pattern argument. + # See https://redis.io/commands/scan#the-match-option for more information. + # Returns an Enumerator that enumerates all SSCAN hits. + def search(key, pattern, &block) + full_key = cache_key(key) + + with do |redis| + exists = redis.exists(full_key) + write(key, yield) unless exists + + redis.sscan_each(full_key, match: pattern) end end end |