[fix] follow up of PR-1856

- `` url: false`` breaks with existing installations
  e92755d358 (r89577339)

- PR-1856: https://github.com/searxng/searxng/pull/1856

- Comments from review: https://github.com/searxng/searxng/pull/1856#pullrequestreview-1176402810

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2022-11-10 20:59:34 +01:00
parent e63457584b
commit ec7c2b1a04
5 changed files with 15 additions and 21 deletions

View File

@ -305,7 +305,7 @@ In this example read/write access is given to the *searxng-redis* group. To get
access rights to redis instance (the socket), your SearXNG (or even your
developer) account needs to be added to the *searxng-redis* group.
``url``
``url``: ``unix:///usr/local/searxng-redis/run/redis.sock?db=0``
URL to connect redis database, see `Redis.from_url(url)`_ & :ref:`redis db`::
redis://[[username]:[password]]@localhost:6379/0
@ -314,20 +314,14 @@ developer) account needs to be added to the *searxng-redis* group.
.. admonition:: Tip for developers
To set up a local redis instance, first set the socket path of the Redis DB
in your YAML setting:
.. code:: yaml
redis:
url: unix:///usr/local/searxng-redis/run/redis.sock?db=0
Then use the following commands to install the redis instance ::
To install a local redis instance that is connected by the default URL use
the following commands::
$ ./manage redis.build
$ sudo -H ./manage redis.install
$ sudo -H ./manage redis.addgrp "${USER}"
# don't forget to logout & login to get member of group
Don't forget to logout & login to get member of group.
.. _settings outgoing:

View File

@ -76,9 +76,9 @@ 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: false
# 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

View File

@ -174,7 +174,7 @@ SCHEMA = {
'default_http_headers': SettingsValue(dict, {}),
},
'redis': {
'url': SettingsValue((None, False, str), False),
'url': SettingsValue((None, False, str), 'unix:///usr/local/searxng-redis/run/redis.sock?db=0'),
},
'ui': {
'static_path': SettingsDirectoryValue(str, os.path.join(searx_dir, 'static')),

View File

@ -26,8 +26,8 @@ import redis
from searx import get_setting
OLD_REDIS_URL_DEFAULT_URL = 'unix:///usr/local/searxng-redis/run/redis.sock?db=0'
"""This was the default Redis URL in settings.yml."""
DEFAULT_URL = 'unix:///usr/local/searxng-redis/run/redis.sock?db=0'
"""This is the default Redis URL."""
_CLIENT = None
logger = logging.getLogger('searx.shared.redisdb')
@ -37,7 +37,7 @@ def client() -> redis.Redis:
return _CLIENT
def initialize():
def init():
global _CLIENT # pylint: disable=global-statement
redis_url = get_setting('redis.url')
if not redis_url:
@ -62,7 +62,7 @@ def initialize():
_CLIENT = None
_pw = pwd.getpwuid(os.getuid())
logger.exception("[%s (%s)] can't connect redis DB ...", _pw.pw_name, _pw.pw_uid)
if redis_url == OLD_REDIS_URL_DEFAULT_URL and isinstance(e, redis.exceptions.ConnectionError):
if redis_url == DEFAULT_URL and isinstance(e, redis.exceptions.ConnectionError):
logger.info(
"You can safely ignore the above Redis error if you don't use Redis. "
"You can remove this error by setting redis.url to false in your settings.yml."

View File

@ -120,7 +120,7 @@ from searx.locales import (
# renaming names from searx imports ...
from searx.autocomplete import search_autocomplete, backends as autocomplete_backends
from searx.languages import language_codes as languages
from searx.shared.redisdb import initialize as redis_initialize
from searx.shared import redisdb
from searx.search import SearchWithPlugins, initialize as search_initialize
from searx.network import stream as http_stream, set_context_network_name
from searx.search.checker import get_result as checker_get_result
@ -1385,7 +1385,7 @@ werkzeug_reloader = flask_run_development or (searx_debug and __name__ == "__mai
if not werkzeug_reloader or (werkzeug_reloader and os.environ.get("WERKZEUG_RUN_MAIN") == "true"):
locales_initialize()
_INFO_PAGES = infopage.InfoPageSet()
redis_initialize()
redisdb.init()
plugin_initialize(app)
search_initialize(enable_checker=True, check_network=True, enable_metrics=settings['general']['enable_metrics'])