mirror of
https://github.com/discourse/discourse.git
synced 2024-12-18 21:30:04 +08:00
2df3c65ba9
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
42 lines
764 B
Ruby
42 lines
764 B
Ruby
# frozen_string_literal: true
|
|
|
|
class RedisSnapshot
|
|
def self.begin_faux_transaction(redis = Discourse.redis)
|
|
@stack ||= []
|
|
@stack.push(RedisSnapshot.load(redis))
|
|
end
|
|
|
|
def self.end_faux_transaction(redis = Discourse.redis)
|
|
@stack.pop.restore(redis)
|
|
end
|
|
|
|
def self.load(redis = Discourse.redis)
|
|
keys = redis.keys
|
|
|
|
values =
|
|
redis.pipelined do |batch|
|
|
keys.each do |key|
|
|
batch.dump(key)
|
|
end
|
|
end
|
|
|
|
new(keys.zip(values).delete_if { |k, v| v.nil? })
|
|
end
|
|
|
|
def initialize(dump)
|
|
@dump = dump
|
|
end
|
|
|
|
def restore(redis = Discourse.redis)
|
|
redis.pipelined do |batch|
|
|
batch.flushdb
|
|
|
|
@dump.each do |key, value|
|
|
batch.restore(key, 0, value)
|
|
end
|
|
end
|
|
|
|
nil
|
|
end
|
|
end
|