Method: Redis::Commands::Keys#migrate

Defined in:
lib/redis/commands/keys.rb

#migrate(key, options) ⇒ String

Transfer a key from the connected instance to another instance.

Parameters:

  • key (String, Array<String>)
  • options (Hash)
    • :host => String: host of instance to migrate to
    • :port => Integer: port of instance to migrate to
    • :db => Integer: database to migrate to (default: same as source)
    • :timeout => Integer: timeout (default: same as connection timeout)
    • :copy => Boolean: Do not remove the key from the local instance.
    • :replace => Boolean: Replace existing key on the remote instance.

Returns:

  • (String)

    "OK"



234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/redis/commands/keys.rb', line 234

def migrate(key, options)
  args = [:migrate]
  args << (options[:host] || raise(':host not specified'))
  args << (options[:port] || raise(':port not specified'))
  args << (key.is_a?(String) ? key : '')
  args << (options[:db] || @client.db).to_i
  args << (options[:timeout] || @client.timeout).to_i
  args << 'COPY' if options[:copy]
  args << 'REPLACE' if options[:replace]
  args += ['KEYS', *key] if key.is_a?(Array)

  send_command(args)
end