summaryrefslogtreecommitdiff
path: root/lib/tasks/cache.rake
diff options
context:
space:
mode:
authorAlfredo Sumaran <alfredo@gitlab.com>2016-02-22 21:15:40 -0500
committerAlfredo Sumaran <alfredo@gitlab.com>2016-02-22 21:15:40 -0500
commit67948368aec144ff7e9997ce184cb4d111622f08 (patch)
treec94e382fb1aca074b6ce503255564828cb387e36 /lib/tasks/cache.rake
parent608012629cc90337aba6c5bd4b2b73b530091fb0 (diff)
parent7c8099853621cc2a244bf6e0fd37a8b503d1ec5e (diff)
downloadgitlab-ce-sidebar-sizing-higher-viewport.tar.gz
Merge branch 'master' into sidebar-sizing-higher-viewportsidebar-sizing-higher-viewport
Diffstat (limited to 'lib/tasks/cache.rake')
-rw-r--r--lib/tasks/cache.rake18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/tasks/cache.rake b/lib/tasks/cache.rake
index 1728dda72cf..9e2fb429d57 100644
--- a/lib/tasks/cache.rake
+++ b/lib/tasks/cache.rake
@@ -1,11 +1,21 @@
namespace :cache do
+ CLEAR_BATCH_SIZE = 1000 # The more the faster, but having too many can crash Ruby
+ REDIS_SCAN_START_STOP = '0' # Magic value, see http://redis.io/commands/scan
+
desc "GitLab | Clear redis cache"
task :clear => :environment do
- # Hack into Rails.cache until https://github.com/redis-store/redis-store/pull/225
- # is accepted (I hope) and we can update the redis-store gem.
redis_store = Rails.cache.instance_variable_get(:@data)
- redis_store.keys.each_slice(1000) do |key_slice|
- redis_store.del(*key_slice)
+ cursor = REDIS_SCAN_START_STOP
+ loop do
+ cursor, keys = redis_store.scan(
+ cursor,
+ match: "#{Gitlab::REDIS_CACHE_NAMESPACE}*",
+ count: CLEAR_BATCH_SIZE
+ )
+
+ redis_store.del(*keys) if keys.any?
+
+ break if cursor == REDIS_SCAN_START_STOP
end
end
end