forked from Archives/searxng
[enh] add redis connector searx/shared/redisdb.py
Add a redis connector, the default DB connector is a socket at:: unix:///usr/local/searxng-redis/run/redis.sock?db=0 To set up a redis instance simply use:: $ ./manage redis.build $ sudo -H ./manage redis.install A hint for developers: To get access rights to this instance, your developer account needs to be added to the *searxng-redis* group:: $ sudo -H ./manage redis.addgrp "${USER}" # don't forget to logout & login to get member of group Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>dependabot/pip/master/sphinx-6.1.3
parent
4f1130d663
commit
a6cfab93fa
@ -0,0 +1,8 @@
|
||||
.. _redis db:
|
||||
|
||||
========
|
||||
Redis DB
|
||||
========
|
||||
|
||||
.. automodule:: searx.shared.redisdb
|
||||
:members:
|
@ -0,0 +1,41 @@
|
||||
# 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
|
||||
import redis
|
||||
from searx import get_setting
|
||||
|
||||
logger = logging.getLogger('searx.shared.redis')
|
||||
|
||||
|
||||
def client():
|
||||
return redis.Redis.from_url(get_setting('redis.url'))
|
||||
|
||||
|
||||
def init():
|
||||
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
|
Loading…
Reference in New Issue