Redis 中文文档 Redis 中文文档
指南
redis.io (opens new window)
指南
redis.io (opens new window)
  • 关于
    • Redis 开源治理
    • Redis 发布周期
    • Redis 赞助商
  • 入门
  • 数据类型
  • Redis Stack
  • 命令
  • 手册

RedisCopy


This utility provides a way to move the contents of one redis DB to another redis DB. It is inspired by the redis-copy.rb script included in the redis source, but aims to always support all object types and to use the most-efficient methods and commands available to your redis versions:

if available on both dbs, will use DUMP /RESTORE commands (redis v2.6+)
if available on source db, will use SCAN instead of KEYS (redis v2.8+)

Installation


  1. ``` sh
  2. $ gem install redis-copy

  3. ```

Usage


The current options can be grabbed using the --help flag.

  1. ``` sh
  2. $ redis-copy --help
  3. redis-copy v1.0.0 (with redis-rb 3.0.6)
  4. Usage: redis-copy [options] <source> <destination>
  5.     <source> and <destination> must be redis connection uris
  6.     like [redis://][:@][:][/]

  7. Specific options:
  8.     -p, --pattern PATTERN            Only transfer matching keys (default *)
  9.                                      See http://redis.io/commands/keys for more info.
  10.     -v, --[no-]verify [PERCENT]      Verify percentage of transfers -- VERY SLOW (default 0)
  11.     -n, --[no-]allow-nonempty        Allow non-empty destination (default false)
  12.     -f, --[no-]fail-fast             Abort on first failure (default false)
  13.         --[no-]pipeline              Pipeline redis commands where available (default true)
  14.     -r, --require FILENAME           Require a script; useful for loading third-party
  15.                                      implementations of key-emitter or copy strategies.
  16.                                      Relative paths *must* begin with `../' or `./'.
  17.     -d, --[no-]debug                 Write debug output (default false)
  18.     -t, --[no-]trace                 Enable backtrace on failure (default false)
  19.         --[no-]prompt                Prompt for confirmation (default true)
  20.         --[no-]dry-run               Output configuration and exit

  21. ```

Example:


  1. ``` sh
  2. $ redis-copy --no-prompt old.redis.host/9 new.redis.host:6380/3
  3. Source:      redis://old.redis.host:6379/9
  4. Destination: redis://new.redis.host:6380/3 (empty)
  5. Key Emitter: Scan
  6. Strategy:    DumpRestore
  7. PROGRESS {:success=>1000, :attempt=>1000}
  8. PROGRESS {:success=>2000, :attempt=>2000}
  9. PROGRESS {:success=>3000, :attempt=>3000}
  10. PROGRESS {:success=>4000, :attempt=>4000}
  11. DONE: {:success=>4246, :attempt=>4246}

  12. ```

Extensibility:


RedisCopy uses the implements gem to define interfaces for key-emitter and copy strategies, so implementations can be supplied by third-parties, secondary gems, or even a local script; the interface shared examples are even available on your load-path so you can ensure your implementation adheres to the interface.

See the existing implementations and their specs for examples, and use the --require command-line flag to load up your own. Since implements treats last-loaded implementations as inherently better, RedisCopy will automatically pick up your implementation and attempt to use it before the bundled implementations.

Contributing


Fork it
Create your feature branch (git checkout -b my-new-feature )
Commit your changes (git commit -am 'Add some feature' )
Push to the branch (git push origin my-new-feature )
Create new Pull Request
Last Updated: 2023-09-03 19:17:54