Sha256: 620d4bad05ebc87c1216e88914673becd02ccec4dac0ef66e3102c24b7438038
Contents?: true
Size: 1.01 KB
Versions: 19
Compression:
Stored size: 1.01 KB
Contents
require 'routemaster/cache_key' module Routemaster module Tasks class FixCacheTTL def initialize(cache: Config.cache_redis, batch_size: 100) @cache = cache @batch_size = batch_size end def call pattern = "#{@cache.namespace}:#{CacheKey::PREFIX}*" _each_key_batch(pattern) do |node, keys| _fix_keys(node, keys) end end private def _each_key_batch(pattern) @cache.redis.nodes.each do |node| cursor = 0 loop do cursor, keys = node.scan(cursor, count: @batch_size, match: pattern) yield node, keys break if cursor.to_i == 0 end end end def _fix_keys(node, keys) ttls = node.pipelined do |p| keys.each { |k| p.ttl(k) } end node.pipelined do |p| keys.zip(ttls).each do |k,ttl| next unless ttl < 0 p.expire(k, Config.cache_expiry) end end end end end end
Version data entries
19 entries across 19 versions & 1 rubygems