BigW Consortium Gitlab

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

6 7
    desc "GitLab | Clear redis cache"
    task redis: :environment do
8
      Gitlab::Redis::Cache.with do |redis|
9 10 11 12
        cursor = REDIS_SCAN_START_STOP
        loop do
          cursor, keys = redis.scan(
            cursor,
13
            match: "#{Gitlab::Redis::Cache::CACHE_NAMESPACE}*",
14 15 16 17 18 19 20
            count: REDIS_CLEAR_BATCH_SIZE
          )

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

          break if cursor == REDIS_SCAN_START_STOP
        end
21
      end
22
    end
23

24
    task all: [:redis]
25
  end
26

27
  task clear: 'cache:clear:redis'
28
end