diff --git a/docs/admin/engines/settings.rst b/docs/admin/engines/settings.rst index 3ac992d3e..8faf64820 100644 --- a/docs/admin/engines/settings.rst +++ b/docs/admin/engines/settings.rst @@ -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: diff --git a/searx/settings.yml b/searx/settings.yml index 21793124d..813dd25b4 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -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 diff --git a/searx/settings_defaults.py b/searx/settings_defaults.py index 470290f92..17386269f 100644 --- a/searx/settings_defaults.py +++ b/searx/settings_defaults.py @@ -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')), diff --git a/searx/shared/redisdb.py b/searx/shared/redisdb.py index ba4a76baa..769f98d8f 100644 --- a/searx/shared/redisdb.py +++ b/searx/shared/redisdb.py @@ -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." diff --git a/searx/webapp.py b/searx/webapp.py index 4f334a9d0..2702d1f67 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -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'])