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

Functions

valkey.Valkey client ()
 initialize ()

Variables

 _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 searx.valkeydb.client ( )

Definition at line 34 of file valkeydb.py.

34def client() -> valkey.Valkey:
35 return _CLIENT
36
37

◆ initialize()

searx.valkeydb.initialize ( )

Definition at line 38 of file valkeydb.py.

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

References searx.get_setting().

Here is the call graph for this function:

Variable Documentation

◆ _CLIENT

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.