ruby Redis使用给定的命名空间过期密钥

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Redis使用给定的命名空间过期密钥相关的知识,希望对你有一定的参考价值。

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

以上是关于ruby Redis使用给定的命名空间过期密钥的主要内容,如果未能解决你的问题,请参考以下文章