From 10e9a42aa060789341505c7c094c5ad354cc2fa8 Mon Sep 17 00:00:00 2001 From: dysonfrost <33471677+dysonfrost@users.noreply.github.com> Date: Mon, 8 Jul 2024 14:10:08 +0200 Subject: [PATCH] Handle non existing redis keys (#63) --- Dockerfile | 4 ++-- pyredis-dump.py | 6 +++++- requirements.txt | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index c26c6ae..9a1477b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ ARG PYTHON_VERSION=alpine -FROM python:$PYTHON_VERSION as base +FROM python:$PYTHON_VERSION AS base ENV APP_ROOT=/app WORKDIR $APP_ROOT @@ -12,7 +12,7 @@ COPY requirements.txt . RUN python -m pip install --upgrade pip && \ python -m pip install -r requirements.txt -FROM base as compile +FROM base AS compile ENV USER_ID=65535 ENV GROUP_ID=65535 diff --git a/pyredis-dump.py b/pyredis-dump.py index 749f1b4..e52afbf 100755 --- a/pyredis-dump.py +++ b/pyredis-dump.py @@ -18,6 +18,8 @@ def __init__(self, *a, **kw): def get_one(self, key): type = self.type(key) + if type == b'none': # Handle non-existing keys gracefully + return None # Or any other appropriate handling p = self.pipeline() p.watch(key) p.multi() @@ -51,7 +53,9 @@ def get_one(self, key): def pattern_iter(self, pattern="*"): for key in self.keys(pattern): - yield self.get_one(key) + result = self.get_one(key) + if result is not None: + yield result def dump(self, outfile=None, pattern="*"): for type, key, ttl, expire_at, value in self.pattern_iter(pattern): diff --git a/requirements.txt b/requirements.txt index 968b7c7..f2ea803 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -ConfigArgParse==1.5.3 -redis==4.3.3 +ConfigArgParse==1.7 +redis==5.0.7