debian-mirror-gitlab/lib/tasks/cache.rake

23 lines
596 B
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
namespace :cache do
2016-04-02 18:10:28 +05:30
CLEAR_BATCH_SIZE = 1000
REDIS_SCAN_START_STOP = '0' # Magic value, see http://redis.io/commands/scan
2015-09-11 14:41:01 +05:30
desc "GitLab | Clear redis cache"
2014-09-02 18:07:02 +05:30
task :clear => :environment do
redis_store = Rails.cache.instance_variable_get(:@data)
2016-04-02 18:10:28 +05:30
cursor = [REDIS_SCAN_START_STOP, []]
loop do
cursor = redis_store.scan(
cursor.first,
match: "#{Gitlab::REDIS_CACHE_NAMESPACE}*",
count: CLEAR_BATCH_SIZE
)
keys = cursor.last
redis_store.del(*keys) if keys.any?
break if cursor.first == REDIS_SCAN_START_STOP
2014-09-02 18:07:02 +05:30
end
end
end