BigW Consortium Gitlab

cache.rake 596 Bytes
Newer Older
1
namespace :cache do
2
  CLEAR_BATCH_SIZE = 1000 # There seems to be no speedup when pushing beyond 1,000
3 4
  REDIS_SCAN_START_STOP = '0' # Magic value, see http://redis.io/commands/scan

5
  desc "GitLab | Clear redis cache"
6
  task :clear => :environment do
7
    redis = Redis.new(url: Gitlab::RedisConfig.url)
8
    cursor = REDIS_SCAN_START_STOP
9
    loop do
10
      cursor, keys = redis.scan(
11
        cursor,
12 13 14 15
        match: "#{Gitlab::REDIS_CACHE_NAMESPACE}*", 
        count: CLEAR_BATCH_SIZE
      )

16
      redis.del(*keys) if keys.any?
17

18
      break if cursor == REDIS_SCAN_START_STOP
19
    end
20 21
  end
end