mirror of
https://github.com/discourse/discourse.git
synced 2025-02-06 19:38:24 +00:00
My theory is that there were nil entries (that we were filtering out) that then changed and we weren't resetting them properly. (the failure no longer repro'd in 30 CI runs in this PR)
35 lines
675 B
Ruby
35 lines
675 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 { |batch| keys.each { |key| batch.dump(key) } }
|
|
|
|
new(keys.zip(values))
|
|
end
|
|
|
|
def initialize(dump)
|
|
@dump = dump
|
|
end
|
|
|
|
def restore(redis = Discourse.redis)
|
|
redis.pipelined do |batch|
|
|
batch.flushdb
|
|
|
|
@dump.each { |key, value| batch.restore(key, 0, value) }
|
|
end
|
|
|
|
nil
|
|
end
|
|
end
|