@@ -499,22 +499,27 @@ def restore(key, ttl, serialized_value, options = {})
499499
500500 # Transfer a key from the connected instance to another instance.
501501 #
502- # @param [String] key
502+ # @param [String, Array<String> ] key
503503 # @param [Hash] options
504504 # - `:host => String`: host of instance to migrate to
505505 # - `:port => Integer`: port of instance to migrate to
506506 # - `:db => Integer`: database to migrate to (default: same as source)
507507 # - `:timeout => Integer`: timeout (default: same as connection timeout)
508+ # - `:copy => Boolean`: Do not remove the key from the local instance.
509+ # - `:replace => Boolean`: Replace existing key on the remote instance.
508510 # @return [String] `"OK"`
509511 def migrate ( key , options )
510- host = options [ :host ] || raise ( RuntimeError , ":host not specified" )
511- port = options [ :port ] || raise ( RuntimeError , ":port not specified" )
512- db = ( options [ :db ] || @client . db ) . to_i
513- timeout = ( options [ :timeout ] || @client . timeout ) . to_i
512+ args = [ :migrate ]
513+ args << ( options [ :host ] || raise ( ':host not specified' ) )
514+ args << ( options [ :port ] || raise ( ':port not specified' ) )
515+ args << ( key . is_a? ( String ) ? key : '' )
516+ args << ( options [ :db ] || @client . db ) . to_i
517+ args << ( options [ :timeout ] || @client . timeout ) . to_i
518+ args << 'COPY' if options [ :copy ]
519+ args << 'REPLACE' if options [ :replace ]
520+ args += [ 'KEYS' , *key ] if key . is_a? ( Array )
514521
515- synchronize do |client |
516- client . call ( [ :migrate , host , port , key , db , timeout ] )
517- end
522+ synchronize { |client | client . call ( args ) }
518523 end
519524
520525 # Delete one or more keys.
0 commit comments