@@ -499,22 +499,27 @@ def restore(key, ttl, serialized_value, options = {})
499
499
500
500
# Transfer a key from the connected instance to another instance.
501
501
#
502
- # @param [String] key
502
+ # @param [String, Array<String> ] key
503
503
# @param [Hash] options
504
504
# - `:host => String`: host of instance to migrate to
505
505
# - `:port => Integer`: port of instance to migrate to
506
506
# - `:db => Integer`: database to migrate to (default: same as source)
507
507
# - `: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.
508
510
# @return [String] `"OK"`
509
511
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 )
514
521
515
- synchronize do |client |
516
- client . call ( [ :migrate , host , port , key , db , timeout ] )
517
- end
522
+ synchronize { |client | client . call ( args ) }
518
523
end
519
524
520
525
# Delete one or more keys.
0 commit comments