Skip to content

Commit

Permalink
Handle non existing redis keys (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
dysonfrost authored Jul 8, 2024
1 parent dc03acc commit 10e9a42
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion pyredis-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ConfigArgParse==1.5.3
redis==4.3.3
ConfigArgParse==1.7
redis==5.0.7

0 comments on commit 10e9a42

Please sign in to comment.