PATTERN = 'order_dispatcher' #'geocode:cache:geocoder' #'users:' #'geocode:cache:geocoder' #
SLEEP = 0.5
res = []
cursor = 0
j = 0
k = 0
db_size = GTRedis.dbsize.to_f
loop do
i = 0
bm = Benchmark.realtime do
cursor, keys = GTRedis.scan(cursor, match: "*#{PATTERN}*", count: 1000)
keys.each do |key|
if GTRedis.ttl(key) > 1.day
# p key
GTRedis.expire(key, 10.minutes)
i += 1
end
end
end
j += i
k += 1000
p "Keys expired: #{i}, took #{bm}. Total keys expired: #{j}, Total keys processed: #{k}. #{(k/db_size*100).round(2)}%"
break if cursor.to_i == 0
# p "Sleepping for #{SLEEP}..."
sleep SLEEP
end