Module: RedisCopy::Strategy
- Extended by:
- Implements::Interface
- Defined in:
- lib/redis-copy/strategy.rb,
lib/redis-copy/strategy/classic.rb,
lib/redis-copy/strategy/dump-restore.rb
Defined Under Namespace
Classes: Classic, DumpRestore
Instance Method Summary collapse
- #copy(key) ⇒ Boolean
- #initialize(source, destination, ui, options = {}) ⇒ Object
- #to_s ⇒ Object
- #verify?(key) ⇒ Boolean
Instance Method Details
#copy(key) ⇒ Boolean
22 23 24 25 |
# File 'lib/redis-copy/strategy.rb', line 22 def copy(key) return super if defined? super raise NotImplementedError end |
#initialize(source, destination, ui, options = {}) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/redis-copy/strategy.rb', line 9 def initialize(source, destination, ui, = {}) @src = source @dst = destination @ui = ui @opt = .dup end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/redis-copy/strategy.rb', line 16 def to_s self.class.name.demodulize end |
#verify?(key) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/redis-copy/strategy.rb', line 27 def verify?(key) @ui.debug("VERIFY: #{key.dump}") type = @src.type(key) template = { args: [key], proc: ->(x){ x }, test: ->(a, b) { a == b } } export_command = case type when 'string' { command: :get } when 'hash' { command: :hgetall } when 'zset' { command: :zrange, args: [key, 0, -1, {with_scores: true}] } when 'set' { command: :smembers, proc: ->(x){ x.to_set} } when 'list' { command: :lrange, args: [key, 0, -1] } else @ui.debug("BORK: #{key.dump} has unknown type #{type.dump}!") return false end # account for drift, ensure within 1 of each other. ttl_command = {command: :ttl, test: ->(a,b){ (a - b).abs <= 1 } } return false unless same_response?(template.merge export_command) return false unless same_response?(template.merge ttl_command) true end |