The checker requires Redis

Remove the abstraction in searx.shared.SharedDict.
Implement a basic and dedicated scheduler for the checker using a Redis script.
This commit is contained in:
Alexandre Flament 2022-07-15 18:38:32 +02:00
parent d764d94a70
commit fe419e355b
12 changed files with 167 additions and 237 deletions

View file

@ -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