- TTL, EXPIRE and EXPIREAT
- Concurrent Modifications
redis-dump-load is a tool for dumping and restoring Redis databases to/from JSON files.
- Supports all Redis data types;
- Dumps TTL and expiration times;
- Can load TTL or original expiration time for expiring keys;
- Can create pretty/human-readable dumps (keys dumped in sorted order, output indented);
- Can stream data when dumping and loading;
- Can be used as a module in a larger program or as a standalone utility;
- Uses an output format compatible with redis-dump.
redis-dump-load can be installed via pip:
pip install redis-dump-load
redisdl.py can be used as a command line tool as follows:
# dump database 0 redis-dump > dump.json redis-dump -o dump.json # load into database 0 redis-load < dump.json redis-load dump.json
The command line options are:
--host HOST: specify redis host
--port PORT: specify redis port
--socket SOCKET_PATH: connect to Unix socket at the specified path
--password PASSWORD: password to use when connecting to redis
--db DATABASE: redis database to connect to (integer)
--keys PATTERN(dumping only): dump only keys matching specified glob-style pattern
-encoding ENCODING: specify encoding to use
--output PATH: write dump to PATH rather than standard output
--pretty(dumping only): pretty-print JSON
--use-expireat(loading only): use
ttlvalues in the dump
--empty(loading only): empty redis data set before loading
--backend BACKEND(loading only): streaming backend to use
redis-dump-load may also be used as a module. API documentation is available on GitHub.
dump will stream data unless the
pretty option is given.
TTL, EXPIRE and EXPIREAT
When dumping, redis-dump-load dumps the TTL values for expiring keys as
well as calculated time when the keys will expire (
expireat). As Redis
does not provide a command to retrieve absolute expiration time of a
key, the expiration time is calculated using the current time on the
client's system. As such, if the time on the client system is not in
sync with time on the system where the Redis server is running,
expireat values will be incorrect.
When loading, redis-dump-load by default uses the TTL values in the dump
ttl key) to set expiration times on the keys in preference to
expireat values. This will maintain the expiration times of the keys
relative to the dump/load time but will change the absolute expiration
time of the keys. Using
--use-expireat command line option
will make redis-dump-load
expireat values in preference to
ttl values, setting expiring
keys to expire at the same absolute time as they had before they were
dumped (as long as system times are in sync on all machines involved).
Redis operates on bytes and has no concept of Unicode or encodings. JSON operates on (Unicode) strings and cannot serialize binary data. Therefore, redis-dump-load has to encode Unicode strings into byte strings when loading data into Redis and decode byte strings into Unicode strings when dumping data from Redis. By default redis-dump-load uses utf-8 for encoding data sent to Redis and decoding data received from Redis. This behavior matches redis-py, whose default encoding is utf-8. A different encoding can be specified.
redis-dump-load does not lock the entire data set it is dumping, because Redis does not provide a way to do so. As a result, modifications to the data set made while a dump is in progress affect the contents of the dump.
Released under the 2 clause BSD license.