From 10ca9aa7173f680f02711c9c51be629f4264a2d2 Mon Sep 17 00:00:00 2001 From: amirreza Date: Wed, 9 Oct 2024 23:10:40 +0330 Subject: [PATCH] async herd docs --- docs/source/async/advanced_configurations.rst | 24 ++++++++++++++++++- docs/source/async/configuration.rst | 24 +++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/docs/source/async/advanced_configurations.rst b/docs/source/async/advanced_configurations.rst index e242ae2..8a07ebc 100644 --- a/docs/source/async/advanced_configurations.rst +++ b/docs/source/async/advanced_configurations.rst @@ -12,9 +12,12 @@ if you need those middlewares, consider using a sync client or implement a new m Clients ####### -as of now, we only have one async client, ``AsyncDefaultClient``, available in ``django_valkey.async_cache.client.default``. +as of now, we have two async client, ``AsyncDefaultClient``, available in ``django_valkey.async_cache.client.default``, and ``AsyncHerdClient`` available in ``django_valkey.async_cache.client.herd``. the default client can also be used with sentinels, as we'll discuss later. +Default client +^^^^^^^^^^^^^^ + the ``AsyncDefaultClient`` is configured by default by ``AsyncValkeyCache``, so if you have configured that as your backend you are all set, but if you want to be explicit or use the client with a different backend you can write it like this: .. code-block:: python @@ -33,6 +36,23 @@ the ``AsyncDefaultClient`` is configured by default by ``AsyncValkeyCache``, so or you can replace the client with your own like that. +Herd client +^^^^^^^^^^^ + +the herd client needs to be configured, but it's as simple as this: + +.. code-block:: python + + CACHES = { + "default": { + "BACKEND": "django_valkey.async_cache.cache.AsyncValkeyCache", + "LOCATION": ["valkey://127.0.0.1:6379"], + "OPTIONS": { + "CLIENT_CLASS": "django_valkey.async_cache.client.AsyncHerdClient", + } + } + } + Connection Factory ################## @@ -51,6 +71,8 @@ the default connection factory is ``AsyncConnectionFactory``, so if you are usin } } + CACHE_HERD_TIMEOUT = 20 # if not set, it's default to 60 + or set it as the global connection factory like this: .. code-block:: python diff --git a/docs/source/async/configuration.rst b/docs/source/async/configuration.rst index db6a575..fc053a1 100644 --- a/docs/source/async/configuration.rst +++ b/docs/source/async/configuration.rst @@ -5,7 +5,10 @@ Configure The Async Client **Important**: the async client is not compatible with django's cache middlewares. if you need the middlewares, consider using the sync client or implement a new middleware. -as of now, we have one async client available, working on more tho. +there are two async clients available, a normal client and a herd client. + +Default client +############## to setup the async client you can configure your settings file to look like this: @@ -14,7 +17,7 @@ to setup the async client you can configure your settings file to look like this CACHES = { "default": { "BACKEND": "django_valkey.async_cache.cache.AsyncValkeyCache", - "LOCATION": "valkey://127.0.0.1:6379"," + "LOCATION": "valkey://127.0.0.1:6379", "OPTIONS": {...}, }, } @@ -24,4 +27,21 @@ And that's it, the backend defaults to use AsyncDefaultClient as client interfac you can, of course configure it to use any other class, or pass in extras args and kwargs, the same way that was discussed at :doc:`../configure/advanced_configurations`. +Herd client +########### + +to set up herd client configure your settings like this: + +.. code-block:: python + + CACHES = { + "default": { + "BACKEND": "django_valkey.async_cache.caches.AsyncValkeyCache", + "LOCATION": "valkey://127.0.0.1:6379", + "OPTIONS": { + "CLIENT_CLASS": "django_valkey.async_cache.client.AsyncHerdClient", + }, + }, + } + for a more specified guide look at :doc:`advanced_configurations`. \ No newline at end of file