From fe419e355bf1527c51e3aee98495d08b89510320 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Fri, 15 Jul 2022 18:38:32 +0200 Subject: The checker requires Redis Remove the abstraction in searx.shared.SharedDict. Implement a basic and dedicated scheduler for the checker using a Redis script. --- searx/shared/redisdb.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'searx/shared/redisdb.py') diff --git a/searx/shared/redisdb.py b/searx/shared/redisdb.py index bb7a0eeb4..d0071f72c 100644 --- a/searx/shared/redisdb.py +++ b/searx/shared/redisdb.py @@ -26,26 +26,20 @@ import redis from searx import get_setting -logger = logging.getLogger('searx.shared.redis') +logger = logging.getLogger('searx.shared.redisdb') _client = None -def client(): - global _client # pylint: disable=global-statement - 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')) +def client() -> redis.Redis: return _client -def init(): +def initialize(): + global _client # pylint: disable=global-statement try: - c = client() - logger.info("connected redis DB --> %s", c.acl_whoami()) - return True + _client = redis.Redis.from_url(get_setting('redis.url')) + logger.info("connected redis: %s", get_setting('redis.url')) except redis.exceptions.ConnectionError as exc: _pw = pwd.getpwuid(os.getuid()) logger.error("[%s (%s)] can't connect redis DB ...", _pw.pw_name, _pw.pw_uid) logger.error(" %s", exc) - return False -- cgit v1.2.3