BigW Consortium Gitlab

cache.rake 611 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 8 9 10 11
    Gitlab::Redis.with do |redis|
      cursor = REDIS_SCAN_START_STOP
      loop do
        cursor, keys = redis.scan(
          cursor,
12
          match: "#{Gitlab::Redis::CACHE_NAMESPACE}*", 
13 14 15 16 17 18 19
          count: CLEAR_BATCH_SIZE
        )
  
        redis.del(*keys) if keys.any?
  
        break if cursor == REDIS_SCAN_START_STOP
      end
20
    end
21 22
  end
end