discourse/lib/tasks/redis.rake
Sam 2df3c65ba9
FIX: add support for pipelined and multi redis commands (#16682)
Latest redis interoduces a block form of multi / pipelined, this was incorrectly
passed through and not namespaced.

Fix also updates logster, we held off on upgrading it due to missing functions
2022-05-10 08:19:02 +10:00

33 lines
714 B
Ruby

# frozen_string_literal: true
task 'redis:clean_up' => ['environment'] do
next unless Rails.configuration.multisite
dbs = RailsMultisite::ConnectionManagement.all_dbs
dbs << Discourse::SIDEKIQ_NAMESPACE
regexp = /((\$(?<message_bus>\w+)$)|(^?(?<namespace>\w+):))/
cursor = 0
redis = Discourse.redis.without_namespace
loop do
cursor, keys = redis.scan(cursor)
cursor = cursor.to_i
redis.multi do |transaction|
keys.each do |key|
if match = key.match(regexp)
db_name = match[:message_bus] || match[:namespace]
if !dbs.include?(db_name)
transaction.del(key)
end
end
end
end
break if cursor == 0
end
end