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

Redis-dump-go


Dump Redis keys to a file. Similar in spirit to https://www.npmjs.com/package/redis-dump and https://github.com/delano/redis-dump but:

Will dump keys across several processes & connections
Uses SCAN rather than KEYS for much reduced memory footprint*with large databases
Easy to deploy & containerize - single binary.
Generates a RESP file rather than a JSON or a list of commands. This is faster to ingest, and recommended by Redis for mass-inserts.

Warning: like similar tools, Redis-dump-go does NOT provide Point-in-Time backups. Please use Redis backups methods when possible.

Features


Dumps all databases present on the Redis server
Keys TTL are preserved by default
Configurable Output (Redis commands, RESP)
Redis password-authentication

Installation


Download the appropriate version for your operating system on ŧhe release page, or use the Docker image :

  1. ``` shell
  2. $ docker run ghcr.io/yannh/redis-dump-go:latest -h
  3. Usage of /redis-dump-go:
  4. [...]
  5. ```

Bandwidth costs: Redis-dump-go is hosted on on Github Container Registry which is currently in Beta. During that period, bandwidth is free. After that period, a Github Account might be required / bandwidth costs might be applicable.

Run


  1. ``` sh
  2. $ ./bin/redis-dump-go -h
  3. Usage of ./bin/redis-dump-go:
  4.   -batchSize int
  5.         HSET/RPUSH/SADD/ZADD only add 'batchSize' items at a time (default 1000)
  6.   -db uint
  7.         only dump this database (default: all databases)
  8.   -filter string
  9.         Key filter to use (default "*")
  10.   -host string
  11.         Server host (default "127.0.0.1")
  12.   -n int
  13.         Parallel workers (default 10)
  14.   -noscan
  15.         Use KEYS * instead of SCAN - for Redis <=2.8
  16.   -output string
  17.         Output type - can be resp or commands (default "resp")
  18.   -port int
  19.         Server port (default 6379)
  20.   -s    Silent mode (disable logging of progress / stats)
  21.   -ttl
  22.         Preserve Keys TTL (default true)

  23. $ ./bin/redis-dump-go > dump.resp
  24. Database 0: 9 element dumped
  25. Database 1: 1 element dumped

  26. ```

For password-protected Redis servers, set the shell variable REDISDUMPGO_AUTH:

  1. ``` sh
  2. $ export REDISDUMPGO_AUTH=myRedisPassword
  3. $ redis-dump-go

  4. ```

Build


Given a correctly configured Go environment:

  1. ``` sh
  2. $ go get github.com/yannh/redis-dump-go
  3. $ cd ${GOPATH}/src/github.com/yannh/redis-dump-go
  4. $ go test ./...
  5. $ go install

  6. ```

Importing the data


  1. ``` sh
  2. redis-cli --pipe < redis-backup.txt

  3. ```

Release Notes & Gotchas


By default, no cleanup is performed before inserting data. When importing the resulting file, hashes, sets and queues will be merged with data already present in the Redis.
Last Updated: 2023-09-03 19:17:54