2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-04 22:39:08 -05:00
|
|
|
task 'redis:clean_up' => ['environment'] do
|
|
|
|
return unless Rails.configuration.multisite
|
|
|
|
|
|
|
|
dbs = RailsMultisite::ConnectionManagement.all_dbs
|
|
|
|
dbs << Discourse::SIDEKIQ_NAMESPACE
|
|
|
|
|
|
|
|
regexp = /((\$(?<message_bus>\w+)$)|(^?(?<namespace>\w+):))/
|
|
|
|
|
|
|
|
cursor = 0
|
2019-12-03 04:05:53 -05:00
|
|
|
redis = Discourse.redis.without_namespace
|
2016-12-04 22:39:08 -05:00
|
|
|
|
|
|
|
loop do
|
|
|
|
cursor, keys = redis.scan(cursor)
|
|
|
|
cursor = cursor.to_i
|
|
|
|
|
|
|
|
redis.multi do
|
|
|
|
keys.each do |key|
|
|
|
|
if match = key.match(regexp)
|
|
|
|
db_name = match[:message_bus] || match[:namespace]
|
|
|
|
|
|
|
|
if !dbs.include?(db_name)
|
|
|
|
redis.del(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
break if cursor == 0
|
|
|
|
end
|
|
|
|
end
|