Skip to content
Commits on Source (2)
default: build upload default: build upload
check:
pycodestyle redisexport/
pylint redisexport/
clean: clean:
rm -rf dist/* rm -rf dist/*
build: clean build: clean
...@@ -7,4 +10,4 @@ test-upload: ...@@ -7,4 +10,4 @@ test-upload:
python3 -m twine upload --repository testpypi dist/* python3 -m twine upload --repository testpypi dist/*
upload: upload:
python3 -m twine upload dist/* python3 -m twine upload dist/*
.PHONY: default clean build upload .PHONY: default check clean build test-upload upload
...@@ -11,7 +11,7 @@ To install redis-export, simply: ...@@ -11,7 +11,7 @@ To install redis-export, simply:
.. code-block:: bash .. code-block:: bash
$ pip install redis-export $ python3 -m pip install redis-export
You should add ~/.local/bin/ to your PATH. You should add ~/.local/bin/ to your PATH.
...@@ -54,10 +54,22 @@ Exported file is a json list, each list item is of form (key, dump_value). ...@@ -54,10 +54,22 @@ 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 The redis key and dump value is encoded in base64 in order to fit in regular
json. json.
Source Code
------------
Source code is hosted at https://gitlab.emacsos.com/sylecn/redis-export
You may clone it via ssh or https protocol
.. code-block:: bash
git clone git@gitlab.emacsos.com:sylecn/redis-export.git
git clone https://gitlab.emacsos.com/sylecn/redis-export.git
License License
---------- ----------
Copyright (C) 2022 Yuanle Song <sylecn@gmail.com> Copyright (C) 2022, 2023 Yuanle Song <sylecn@gmail.com>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -75,6 +87,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -75,6 +87,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
ChangeLog 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 * v0.2.0 2022-09-24
- update README.rst, applied license, distributed on PyPI. - update README.rst, applied license, distributed on PyPI.
......
...@@ -5,4 +5,4 @@ ...@@ -5,4 +5,4 @@
""" """
__version__ = "0.2.0" __version__ = "0.3.0"
#!/usr/bin/env python3 #!/usr/bin/env python3
# coding=utf-8 # coding=utf-8
# #
# Copyright (C) 2022 Yuanle Song <sylecn@gmail.com> # Copyright (C) 2022, 2023 Yuanle Song <sylecn@gmail.com>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
...@@ -25,6 +25,8 @@ import argparse ...@@ -25,6 +25,8 @@ import argparse
import logging import logging
import codecs import codecs
import json import json
import os
from getpass import getpass
import redis import redis
...@@ -34,14 +36,14 @@ from redisexport import __version__ ...@@ -34,14 +36,14 @@ from redisexport import __version__
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def tob64(bs): def tob64(bs): # pylint: disable=invalid-name
"""encode bytes to base64 string. """encode bytes to base64 string.
""" """
return codecs.decode(codecs.encode(bs, 'base64')) return codecs.decode(codecs.encode(bs, 'base64'))
def fromb64(s): def fromb64(s): # pylint: disable=invalid-name
"""decode base64 string to bytes. """decode base64 string to bytes.
""" """
...@@ -49,7 +51,19 @@ def fromb64(s): ...@@ -49,7 +51,19 @@ def fromb64(s):
def get_redis(args): def get_redis(args):
return redis.Redis(host=args.host, port=args.port, db=args.num) if args.uri:
return redis.Redis.from_url(args.uri)
if args.askpass:
password = getpass()
elif args.password:
password = args.password
elif os.getenv('REDISCLI_AUTH'):
password = os.getenv('REDISCLI_AUTH')
else:
password = None
return redis.Redis(host=args.host, port=args.port, db=args.num,
password=password)
def export_db(args): def export_db(args):
...@@ -94,6 +108,16 @@ def create_shared_parser(): ...@@ -94,6 +108,16 @@ def create_shared_parser():
parser.add_argument('--host', default='localhost', help='redis host') parser.add_argument('--host', default='localhost', help='redis host')
parser.add_argument('-p', '--port', default=6379, help='redis port') parser.add_argument('-p', '--port', default=6379, help='redis port')
parser.add_argument('-n', '--num', help='redis database number') parser.add_argument('-n', '--num', help='redis database number')
parser.add_argument('-a', '--pass', dest='password',
help='''Password to use when connecting to the server.
You can also use the REDISCLI_AUTH environment
variable to pass this password more safely
(if both are used, this argument takes precedence).''')
parser.add_argument('--askpass', action='store_true',
help='''Force user to input password with mask from '
STDIN. If this argument is used, '-a' and REDISCLI_AUTH
environment variable will be ignored.''')
parser.add_argument('-u', metavar='URI', dest='uri', help='Server URI.')
return parser return parser
......