Skip to content

Commit 0f4c411

Browse files
committed
added the new base class, fixed typos and renames
1 parent 5868415 commit 0f4c411

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

docs/source/customize.rst

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Customizing django-valkey
33
=========================
44

5-
The basics of how to intrduce your own classes to be used by django-valkeey has been discussed in length in :doc:`configure/advanced_configurations`.
5+
The basics of how to introduce your own classes to be used by django-valkey has been discussed in length in :doc:`configure/advanced_configurations`.
66

7-
in this section we're going to look at two base classes that django-valkey provides and you can use them to write your classes faster.
7+
in this section we're going to look at the base classes that django-valkey provides and you can use them to write your classes faster.
88

9-
django-valkey comes with two base classes: ``django_valkey.base.BaseValkeyCache`` and ``django_valkey.base_pool.BaseConnectionPool``.
9+
django-valkey comes with three base classes: ``django_valkey.base.BaseValkeyCache``, ``django_valkey.base_client.BaseClient`` and ``django_valkey.base_pool.BaseConnectionFactory``.
1010

1111
BaseValkeyCache
1212
###############
@@ -22,6 +22,8 @@ to inherit from this base class you can take the example of our own cache backen
2222
.. code-block:: python
2323
2424
from valkey import Valkey
25+
26+
from django_valkey.base import BaseValkeyCache
2527
from django_valkey.client import DefaultClient
2628
2729
class ValkeyCache(BaseValkeyCache[DefaultClient, Valkey]):
@@ -33,10 +35,33 @@ the class attribute defined in the example is **mandatory**, it is so we can hav
3335
``BaseValkeyCache`` has both *sync* and *async* methods implemented, but there is no logic in them, most methods need to be overwritten.
3436

3537

36-
BaseConnectionPool
38+
BaseClient
39+
##########
40+
``BaseClient`` inherits from ``typing.Generic`` to make cleaner type hints.
41+
this class has all the logic necessary for a cache client (it is a copy of the old DefaultClient class), it finds the different servers and connects to them, add has all the commands that valkey supports.
42+
43+
the ``typing.Generic`` needs a backend to be passed in, e.g: ``valkey.Valkey``
44+
45+
the base class also needs the subclasses to have a ``CONNECTION_FACTORY_PATH`` class variable pointing to the connection factory class.
46+
47+
an example code would look like this:
48+
49+
.. code-block:: python
50+
51+
from valkey import Valkey
52+
53+
from django_valkey.base_client import BaseClient
54+
55+
class DefaultClient(BaseClient[Valkey]):
56+
CONNECTION_FACTORY_PATH = "django_valkey.pool.ConnectionFactory"
57+
58+
*note* that CONNECTION_FACTORY_PATH is only used if ``DJANGO_VALKEY_CONNECTION_FACTORY`` is not set.
59+
60+
61+
BaseConnectionFactory
3762
##################
3863

39-
the ``BaseConnectionPool`` inherits from ``typing.Generic`` to give more robust type hinting, and allow our four connection pools to have cleaner codebase.
64+
the ``BaseConnectionFactory`` inherits from ``typing.Generic`` to give more robust type hinting, and allow our four connection pools to have cleaner codebase.
4065

4166
to inherit from this class you need to pass in the underlying backend that you are using and the connection pool, for example this is one of the connection pools in this project:
4267

@@ -45,6 +70,8 @@ to inherit from this class you need to pass in the underlying backend that you a
4570
from valkey import Valkey
4671
from valkey.connection import ConnectionPool
4772
73+
from django_valkey.base_pool import BaseConnectionFactory
74+
4875
4976
class ConnectionFactory(BaseConnectionPool[Valkey, ConnectionPool]):
5077
path_pool_cls = "valkey.connection.ConnectionPool"

0 commit comments

Comments
 (0)