diff options
Diffstat (limited to 'searx')
| -rw-r--r-- | searx/settings.yml | 4 | ||||
| -rw-r--r-- | searx/settings_defaults.py | 3 | ||||
| -rw-r--r-- | searx/shared/redisdb.py | 50 | ||||
| -rw-r--r-- | searx/templates/oscar/preferences.html | 2 | ||||
| -rw-r--r-- | searx/templates/simple/preferences.html | 2 |
5 files changed, 59 insertions, 2 deletions
diff --git a/searx/settings.yml b/searx/settings.yml index d2c466cb0..0ea69007a 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -62,6 +62,10 @@ server: X-Robots-Tag: noindex, nofollow Referrer-Policy: no-referrer +redis: + # https://redis-py.readthedocs.io/en/stable/connections.html#redis.client.Redis.from_url + url: unix:///usr/local/searxng-redis/run/redis.sock?db=0 + ui: # Custom static path - leave it blank if you didn't change static_path: "" diff --git a/searx/settings_defaults.py b/searx/settings_defaults.py index e84b442fe..ff556e3bb 100644 --- a/searx/settings_defaults.py +++ b/searx/settings_defaults.py @@ -170,6 +170,9 @@ SCHEMA = { 'method': SettingsValue(('POST', 'GET'), 'POST'), 'default_http_headers': SettingsValue(dict, {}), }, + 'redis': { + 'url': SettingsValue(str, 'unix:///usr/local/searxng-redis/run/redis.sock?db=0'), + }, 'ui': { 'static_path': SettingsDirectoryValue(str, os.path.join(searx_dir, 'static')), 'templates_path': SettingsDirectoryValue(str, os.path.join(searx_dir, 'templates')), diff --git a/searx/shared/redisdb.py b/searx/shared/redisdb.py new file mode 100644 index 000000000..d6a4dc3bf --- /dev/null +++ b/searx/shared/redisdb.py @@ -0,0 +1,50 @@ +# 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 diff --git a/searx/templates/oscar/preferences.html b/searx/templates/oscar/preferences.html index fe86ce39b..c579c6010 100644 --- a/searx/templates/oscar/preferences.html +++ b/searx/templates/oscar/preferences.html @@ -322,7 +322,7 @@ </noscript> <div class="tab-pane{% if loop.first %} active{% endif %} active_if_nojs" id="tab_engine_{{ categ|replace(' ', '_') }}"> {% if categ == OTHER_CATEGORY %} - <p>{{_('This tab does not show up for search results but you can search the engines listed here via bangs.')}}</p> + <p>{{_('This tab does not show up for search results, but you can search the engines listed here via bangs.')}}</p> {% endif %} <div class="container-fluid"> <fieldset> diff --git a/searx/templates/simple/preferences.html b/searx/templates/simple/preferences.html index 043f9d634..7c2a2adf9 100644 --- a/searx/templates/simple/preferences.html +++ b/searx/templates/simple/preferences.html @@ -277,7 +277,7 @@ {% for categ in categories_as_tabs + [OTHER_CATEGORY] %} {{ tab_header('enginetab', 'category' + categ, _(categ)) }} {% if categ == OTHER_CATEGORY %} - <p>{{_('This tab does not show up for search results but you can search the engines listed here via bangs.')}}</p> + <p>{{_('This tab does not show up for search results, but you can search the engines listed here via bangs.')}}</p> {% endif %} <div class="scrollx"> <table class="striped"> |