From afdeecaecc96d352487ad9529adef3828dd30865 Mon Sep 17 00:00:00 2001 From: John Loehrer <72squared@gmail.com> Date: Thu, 10 Nov 2022 05:50:14 -0800 Subject: [PATCH] upgrade to redis-py 4 and get rid of redis-py-cluster --- Dockerfile | 28 ++++++++++++++++++++++++++++ redisimp/VERSION | 2 +- redisimp/api.py | 18 +++++++----------- redisimp/cli.py | 22 ++++++++++------------ requirements.txt | 7 +++---- setup.py | 4 ++-- test.py | 3 +-- 7 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..204ebe5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# +# USAGE: +# docker build -t redisimp ./ +# docker run --entrypoint redisimp redisimp -s ip1:6379 -d ip2:6379 + + +FROM python AS build +RUN pip install --upgrade pip + + +COPY ./ ./ + +RUN pip install -r dev-requirements.txt + +RUN python3 setup.py bdist_wheel + + +FROM python + +RUN pip install --upgrade pip + +COPY --from=build ./dist/redisimp-*-py3-none-any.whl ./ + +RUN pip install ./redisimp-*-py3-none-any.whl + +RUN rm ./redisimp-*-py3-none-any.whl + +ENTRYPOINT ["redisimp"] \ No newline at end of file diff --git a/redisimp/VERSION b/redisimp/VERSION index 0d91a54..1d0ba9e 100644 --- a/redisimp/VERSION +++ b/redisimp/VERSION @@ -1 +1 @@ -0.3.0 +0.4.0 diff --git a/redisimp/api.py b/redisimp/api.py index 655cdde..5d1a9cc 100644 --- a/redisimp/api.py +++ b/redisimp/api.py @@ -1,9 +1,5 @@ import re - -try: - import rediscluster -except ImportError: - rediscluster = None +import redis from .rdbparser import parse_rdb import fnmatch from six import string_types @@ -99,7 +95,7 @@ def normalize(v): def _supports_replace(conn): - if rediscluster and isinstance(conn, rediscluster.RedisCluster): + if isinstance(conn, redis.RedisCluster): return True version = conn.info().get('redis_version') if not version: @@ -145,7 +141,7 @@ def _clobber_copy(src, dst, pattern=None): yields the keys it processes as it goes. :param pattern: :param src: redis.StrictRedis - :param dst: redis.StrictRedis or rediscluster.RedisCluster + :param dst: redis.StrictRedis or redis.RedisCluster :return: None """ read = _read_data_and_pttl @@ -164,7 +160,7 @@ def _backfill_copy(src, dst, pattern=None): yields the keys it processes as it goes. WON'T OVERWRITE the key if it exists. It'll skip over it. :param src: redis.StrictRedis - :param dst: redis.StrictRedis or rediscluster.RedisCluster + :param dst: redis.StrictRedis or redis.RedisCluster :param pattern: str :return: None """ @@ -228,7 +224,7 @@ def _rdb_clobber_copy(src, dst, pattern=None): yields the keys it processes as it goes. :param pattern: :param src: redis.StrictRedis - :param dst: redis.StrictRedis or rediscluster.RedisCluster + :param dst: redis.StrictRedis or redis.RedisCluster :return: None """ _restore = _get_restore_handler(dst) @@ -249,7 +245,7 @@ def _rdb_dryrun_copy(src, pattern=None): yields the keys it processes as it goes. WON'T OVERWRITE the key if it exists. It'll skip over it. :param src: redis.StrictRedis - :param dst: redis.StrictRedis or rediscluster.RedisCluster + :param dst: redis.StrictRedis or redis.RedisCluster :param pattern: str :return: None """ @@ -266,7 +262,7 @@ def _rdb_backfill_copy(src, dst, pattern=None): yields the keys it processes as it goes. WON'T OVERWRITE the key if it exists. It'll skip over it. :param src: redis.StrictRedis - :param dst: redis.StrictRedis or rediscluster.RedisCluster + :param dst: redis.StrictRedis or redis.RedisCluster :param pattern: str :return: None """ diff --git a/redisimp/cli.py b/redisimp/cli.py index ad04851..af5037e 100644 --- a/redisimp/cli.py +++ b/redisimp/cli.py @@ -1,15 +1,11 @@ # std lib import argparse +import logging import sys import time -import logging from signal import signal, SIGTERM # 3rd party -try: - import rediscluster -except ImportError: - rediscluster = None import redis import redislite from redis.exceptions import BusyLoadingError @@ -122,13 +118,15 @@ def resolve_destination(dststring): if not conn.info('cluster').get('cluster_enabled', None): return conn - if not rediscluster: - raise RuntimeError( - 'cluster destination specified and redis-py-cluster not installed') - - host, port = dststring.split(':') - return rediscluster.RedisCluster( - startup_nodes=[{'host': host, 'port': port}], max_connections=1000) + if dststring.startswith("redis://") or \ + dststring.startswith("rediss://") or \ + dststring.startswith("unix://"): + return redis.RedisCluster.from_url( + dststring, max_connections=1000) + else: + return redis.RedisCluster.from_url( + "redis://{dststring}".format(dststring=dststring), + max_connections=1000) # pylint: disable=unused-argument diff --git a/requirements.txt b/requirements.txt index ddc7531..85ab9aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ -redislite>=5.0.165407 -# @akretschmar: sticking with redis 3.x; bumping to 4.x created dependency conflicts; not worth fighting right now -redis>=3.5.3 -redis-py-cluster>=2.1.0 +psutil +redislite +redis six diff --git a/setup.py b/setup.py index 0990b7f..fe0d6f2 100755 --- a/setup.py +++ b/setup.py @@ -63,8 +63,8 @@ def run(self): 'Environment :: Web Environment', 'Operating System :: POSIX'], license='MIT', - install_requires=['redis>=2.10.2', 'redislite>=3.0.0', 'six'], - tests_require=['redislite>=3.0.271', 'redis-py-cluster>=1.3.0'], + install_requires=['redis>=4.3.4', 'redislite>=6.0.0', 'six'], + tests_require=[], include_package_data=True, long_description=readme, entry_points={'console_scripts': ['redisimp = redisimp.cli:main']}, diff --git a/test.py b/test.py index 1c569c1..ae0c983 100755 --- a/test.py +++ b/test.py @@ -8,7 +8,6 @@ # 3rd party import redis import redislite -import rediscluster import redislite.patch # our package @@ -27,7 +26,7 @@ def flush_redis_data(conn): if conn is None: return - if rediscluster and isinstance(conn, rediscluster.RedisCluster): + if isinstance(conn, redis.RedisCluster): conns = [redis.StrictRedis(host=node['host'], port=node['port']) for node in conn.connection_pool.nodes.nodes.values() if node.get('server_type', None) == 'master']