searxng/searx/shared/redisdb.py
Markus Heiser 50c4b58db6 [hotfix] interim fix to get docker-build of CI without issues
There is an issue with redis v4.1.0 [1] / for the interim lets remove this
python dependency.

[1] https://github.com/searxng/searxng/issues/741

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2022-01-12 09:31:12 +01:00

51 lines
1.3 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
"""Implementation of the redis client (redis-py_).
.. _redis-py: https://github.com/redis/redis-py
This implementation uses the :ref:`settings redis` setup from ``settings.yml``.
A redis DB connect can be tested by::
>>> from searx.shared import redisdb
>>> redisdb.init()
True
>>> db = redisdb.client()
>>> db.set("foo", "bar")
True
>>> db.get("foo")
b'bar'
>>>
"""
import logging
from searx import get_setting
logger = logging.getLogger('searx.shared.redis')
_client = None
def client():
global _client # pylint: disable=global-statement
import redis # pylint: disable=import-error, import-outside-toplevel
if _client is None:
# not thread safe: in the worst case scenario, two or more clients are
# initialized only one is kept, the others are garbage collected.
_client = redis.Redis.from_url(get_setting('redis.url'))
return _client
def init():
import redis # pylint: disable=import-error, import-outside-toplevel
try:
c = client()
logger.info("connected redis DB --> %s", c.acl_whoami())
return True
except redis.exceptions.ConnectionError as exc:
logger.error("can't connet redis DB ...")
logger.error(" %s", exc)
return False