Skip to content

Commit

Permalink
Implement redis retries
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed Feb 21, 2024
1 parent 3311484 commit a587400
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
6 changes: 6 additions & 0 deletions acoustid/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from optparse import OptionParser
from typing import Any, Optional

import redis.retry
import redis.backoff
from redis import Redis
from redis.sentinel import Sentinel as RedisSentinel
from statsd import StatsClient
Expand Down Expand Up @@ -63,16 +65,20 @@ def __init__(self, config_path, tests=False):
self.redis = None
self.redis_sentinel = None

redis_retry = redis.retry.Retry(redis.backoff.ExponentialBackoff(), 2)

if self.config.redis.sentinel:
self.redis_sentinel = RedisSentinel(
[(self.config.redis.host, self.config.redis.port)],
password=self.config.redis.password,
retry=redis_retry,
)
else:
self.redis = Redis(
host=self.config.redis.host,
port=self.config.redis.port,
password=self.config.redis.password,
retry=redis_retry,
)

self._console_logging_configured = False
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Jinja2
python-openid; python_version < "3"
python3-openid; python_version >= "3"
Markdown
redis
redis>=5
flask>=2
rauth
cryptography>=3.3.2
Expand Down
8 changes: 2 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.8
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements.txt requirements.in
Expand Down Expand Up @@ -44,8 +44,6 @@ gunicorn==20.1.0
# via -r requirements.in
idna==2.8
# via requests
importlib-metadata==7.0.1
# via flask
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
Expand Down Expand Up @@ -89,7 +87,7 @@ pytz==2019.3
# via -r requirements.in
rauth==0.7.3
# via -r requirements.in
redis==4.4.4
redis==5.0.1
# via -r requirements.in
requests==2.31.0
# via
Expand All @@ -116,8 +114,6 @@ werkzeug==2.3.8
# via
# -r requirements.in
# flask
zipp==3.17.0
# via importlib-metadata
zope-event==4.5.0
# via gevent
zope-interface==5.2.0
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ types-requests ; python_version >= "3"
types-click ; python_version >= "3"
types-six ; python_version >= "3"
types-pytz ; python_version >= "3"
types-redis ; python_version >= "3"
types-redis>=4.6.0
20 changes: 17 additions & 3 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
#
# This file is autogenerated by pip-compile with Python 3.8
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements_dev.txt requirements_dev.in
#
black==23.3.0
# via -r requirements_dev.in
cffi==1.15.1
# via
# -c requirements.txt
# cryptography
click==8.1.3
# via
# -c requirements.txt
# black
cryptography==39.0.1
# via
# -c requirements.txt
# types-pyopenssl
# types-redis
exceptiongroup==1.1.1
# via pytest
flake8==5.0.4
Expand Down Expand Up @@ -40,6 +49,10 @@ pluggy==1.0.0
# via pytest
pycodestyle==2.9.1
# via flake8
pycparser==2.19
# via
# -c requirements.txt
# cffi
pyflakes==2.5.0
# via flake8
pytest==7.3.1
Expand All @@ -53,16 +66,17 @@ tomli==1.2.3
# pytest
types-click==7.1.5 ; python_version >= "3"
# via -r requirements_dev.in
types-pyopenssl==24.0.0.20240130
# via types-redis
types-pytz==2021.1.2 ; python_version >= "3"
# via -r requirements_dev.in
types-redis==3.5.6 ; python_version >= "3"
types-redis==4.6.0.20240218
# via -r requirements_dev.in
types-requests==2.25.6 ; python_version >= "3"
# via -r requirements_dev.in
types-six==0.1.9 ; python_version >= "3"
# via -r requirements_dev.in
typing-extensions==3.10.0.0
# via
# black
# mypy
# sqlalchemy-stubs
10 changes: 5 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py3.8, py3.10, mypy, flake8, isort, black
envlist = py3.10, mypy, flake8, isort, black
skip_missing_interpreters = true
skipsdist = true

Expand All @@ -12,29 +12,29 @@ deps =
commands = pytest -v tests/

[testenv:mypy]
basepython = python3
basepython = python3.10
skip_install = true
deps =
-rrequirements.txt
-rrequirements_dev.txt
commands = mypy acoustid/ tests/

[testenv:flake8]
basepython = python3
basepython = python3.10
skip_install = true
deps =
-rrequirements_dev.txt
commands = flake8 acoustid/ tests/

[testenv:isort]
basepython = python3
basepython = python3.10
skip_install = true
deps =
-rrequirements_dev.txt
commands = isort --check acoustid/ tests/

[testenv:black]
basepython = python3
basepython = python3.10
skip_install = true
deps =
-rrequirements_dev.txt
Expand Down

0 comments on commit a587400

Please sign in to comment.