Skip to main content

Export redis keys with a prefix or matching a pattern, import from exported file

Project description

Export redis keys with a given prefix or pattern, which later can be imported to another redis server. To export all keys, use ‘*’ as pattern.

Installation

To install redis-export, simply:

$ python3 -m pip install redis-export

You should add ~/.local/bin/ to your PATH.

Quick Start

redis-export PREFIX_OR_PATTERN OUTPUT_FILE
redis-import INPUT_FILE

For example,

# prefix based export
redis-export 'phonebook:' ~/d/t1.json
# pattern based export
# redis-export 'phonebook:*:name:*' ~/d/t1.json
redis-import --host redis.example.com ~/d/t1.json

For more usage help, run the command with --help option.

Documentation

redis-export will export keys with given pattern to a json file (keys and values both base64 encoded).

redis-import will import those keys and values back to redis.

Implementation Detail

  • SCAN is used to iterate over keys with given pattern.

  • DUMP is used to dump the key.

  • RESTORE is used to restore a key. force-replace param is set to TRUE.

Exported file is a json list, each list item is of form (key, dump_value). The redis key and dump value is encoded in base64 in order to fit in regular json.

Source Code

Source code is hosted at https://gitlab.emacsos.com/sylecn/redis-export

You may clone it via ssh or https protocol

git clone git@gitlab.emacsos.com:sylecn/redis-export.git
git clone https://gitlab.emacsos.com/sylecn/redis-export.git

License

Copyright (C) 2022, 2023 Yuanle Song <sylecn@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

ChangeLog

  • v0.3.0 2023-03-13

    • support auth related options. Use the same options as redis-cli.

    • add source code URL in README.rst

  • v0.2.0 2022-09-24

    • update README.rst, applied license, distributed on PyPI.

  • v0.1.2 2022-09-18

    • bugfix: when pattern contains ‘*’ should not error

  • v0.1.0 2021-11-21

    • initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redis-export-0.3.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redis_export-0.3.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file redis-export-0.3.1.tar.gz.

File metadata

  • Download URL: redis-export-0.3.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.2

File hashes

Hashes for redis-export-0.3.1.tar.gz
Algorithm Hash digest
SHA256 eecc6664fd4132923cebd37a3b299f8d4754756ff25f45b74186ca194d44ed56
MD5 f72a47340bd84ff970f631950f7132db
BLAKE2b-256 f50cd88cb694930d69ef01359cc7c83ef3e02f3a4f1154aaf6b213a103101fe7

See more details on using hashes here.

File details

Details for the file redis_export-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: redis_export-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.2

File hashes

Hashes for redis_export-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d9f53795f9a2fd2d3e418af4fc268de5f656bf9d72fb39e52ef7fd910251a502
MD5 a0e55937bcd7f79b74fc4ca1e474370f
BLAKE2b-256 93b29c6528b12e910896a14bdc296f690d328df0afdda526321d90a954cf0e74

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page