2013-03-31 16:45:58 -04:00
|
|
|
namespace :cache do
|
2016-10-06 17:17:11 -04:00
|
|
|
namespace :clear do
|
|
|
|
REDIS_CLEAR_BATCH_SIZE = 1000 # There seems to be no speedup when pushing beyond 1,000
|
2017-02-22 13:18:40 -05:00
|
|
|
REDIS_SCAN_START_STOP = '0'.freeze # Magic value, see http://redis.io/commands/scan
|
2016-02-18 10:55: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
|
2017-07-10 23:35:47 -04:00
|
|
|
Gitlab::Redis::Cache.with do |redis|
|
2018-04-09 08:41:55 -04:00
|
|
|
cache_key_pattern = %W[#{Gitlab::Redis::Cache::CACHE_NAMESPACE}*
|
|
|
|
projects/*/pipeline_status]
|
2016-10-06 17:17:11 -04:00
|
|
|
|
2018-04-09 08:41:55 -04: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
|
|
|
|
2020-06-24 17:08:46 -04:00
|
|
|
Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do
|
|
|
|
redis.del(*keys) if keys.any?
|
|
|
|
end
|
2018-04-09 08:41:55 -04:00
|
|
|
|
|
|
|
break if cursor == REDIS_SCAN_START_STOP
|
|
|
|
end
|
2016-10-06 17:17:11 -04:00
|
|
|
end
|
2016-03-16 13:10:03 -04:00
|
|
|
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
|