.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.valkeydb Namespace Reference

Functions

valkey.Valkey|None client ()
 initialize ()

Variables

valkey _CLIENT = None
 logger = logging.getLogger(__name__)

Detailed Description

Implementation of the valkey client (valkey-py_).

.. _valkey-py: https://github.com/valkey-io/valkey-py

This implementation uses the :ref:`settings valkey` setup from ``settings.yml``.
A valkey DB connect can be tested by::

  >>> from searx import valkeydb
  >>> valkeydb.initialize()
  True
  >>> db = valkeydb.client()
  >>> db.set("foo", "bar")
  True
  >>> db.get("foo")
  b'bar'
  >>>

Function Documentation

◆ client()

valkey.Valkey | None searx.valkeydb.client ( )
Returns SearXNG's global Valkey DB connector (Valkey client object).

Definition at line 34 of file valkeydb.py.

34def client() -> valkey.Valkey | None:
35 """Returns SearXNG's global Valkey DB connector (Valkey client object)."""
36 return _CLIENT
37
38

◆ initialize()

searx.valkeydb.initialize ( )

Definition at line 39 of file valkeydb.py.

39def initialize():
40 global _CLIENT # pylint: disable=global-statement
41 if get_setting('redis.url'):
42 warnings.warn("setting redis.url is deprecated, use valkey.url", DeprecationWarning)
43 valkey_url = get_setting('valkey.url') or get_setting('redis.url')
44 if not valkey_url:
45 return False
46 try:
47 # create a client, but no connection is done
48 _CLIENT = valkey.Valkey.from_url(valkey_url)
49
50 # log the parameters as seen by the valkey lib, without the password
51 kwargs = _CLIENT.get_connection_kwargs().copy()
52 kwargs.pop('password', None)
53 kwargs = ' '.join([f'{k}={v!r}' for k, v in kwargs.items()])
54 logger.info("connecting to Valkey %s", kwargs)
55
56 # check the connection
57 _CLIENT.ping()
58
59 # no error: the valkey connection is working
60 logger.info("connected to Valkey")
61 return True
62 except valkey.exceptions.ValkeyError:
63 _CLIENT = None
64 _pw = pwd.getpwuid(os.getuid())
65 logger.exception("[%s (%s)] can't connect valkey DB ...", _pw.pw_name, _pw.pw_uid)
66 return False

References searx.get_setting().

Here is the call graph for this function:

Variable Documentation

◆ _CLIENT

valkey searx.valkeydb._CLIENT = None
protected

Definition at line 30 of file valkeydb.py.

◆ logger

searx.valkeydb.logger = logging.getLogger(__name__)

Definition at line 31 of file valkeydb.py.