2021-02-05 07:09:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-03-31 16:45:58 -04:00
|
|
|
namespace :cache do
|
2016-10-06 17:17:11 -04:00
|
|
|
namespace :clear do
|
2021-03-03 19:11:19 -05:00
|
|
|
REDIS_CLEAR_BATCH_SIZE = 1000 # There seems to be no speedup when pushing beyond 1,000
|
2021-03-25 23:09:21 -04:00
|
|
|
REDIS_SCAN_START_STOP = '0' # Magic value, see http://redis.io/commands/scan
|
2021-03-03 19:11:19 -05:00
|
|
|
|
2020-01-23 01:08:32 -05:00
|
|
|
desc "GitLab | Cache | Clear redis cache"
|
2016-10-06 17:17:11 -04:00
|
|
|
task redis: :environment do
|
2021-03-03 19:11:19 -05:00
|
|
|
Gitlab::Redis::Cache.with do |redis|
|
|
|
|
cache_key_pattern = %W[#{Gitlab::Redis::Cache::CACHE_NAMESPACE}*
|
|
|
|
projects/*/pipeline_status]
|
2016-10-06 17:17:11 -04:00
|
|
|
|
2021-03-03 19:11:19 -05:00
|
|
|
cache_key_pattern.each do |match|
|
|
|
|
cursor = REDIS_SCAN_START_STOP
|
|
|
|
loop do
|
|
|
|
cursor, keys = redis.scan(
|
|
|
|
cursor,
|
|
|
|
match: match,
|
|
|
|
count: REDIS_CLEAR_BATCH_SIZE
|
|
|
|
)
|
2016-10-06 17:17:11 -04:00
|
|
|
|
2021-03-03 19:11:19 -05:00
|
|
|
Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do
|
|
|
|
redis.del(*keys) if keys.any?
|
|
|
|
end
|
2018-04-09 08:41:55 -04:00
|
|
|
|
2021-03-03 19:11:19 -05:00
|
|
|
break if cursor == REDIS_SCAN_START_STOP
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-06-20 07:58:57 -04:00
|
|
|
end
|
2016-10-06 17:17:11 -04:00
|
|
|
|
2017-04-10 14:50:48 -04:00
|
|
|
task all: [:redis]
|
2013-03-31 16:45:58 -04:00
|
|
|
end
|
2016-10-06 17:17:11 -04:00
|
|
|
|
2016-10-22 07:42:19 -04:00
|
|
|
task clear: 'cache:clear:redis'
|
2013-03-31 16:45:58 -04:00
|
|
|
end
|