You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/customize.rst
+32-5Lines changed: 32 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,11 @@
2
2
Customizing django-valkey
3
3
=========================
4
4
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`.
6
6
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.
8
8
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``.
10
10
11
11
BaseValkeyCache
12
12
###############
@@ -22,6 +22,8 @@ to inherit from this base class you can take the example of our own cache backen
@@ -33,10 +35,33 @@ the class attribute defined in the example is **mandatory**, it is so we can hav
33
35
``BaseValkeyCache`` has both *sync* and *async* methods implemented, but there is no logic in them, most methods need to be overwritten.
34
36
35
37
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.
*note* that CONNECTION_FACTORY_PATH is only used if ``DJANGO_VALKEY_CONNECTION_FACTORY`` is not set.
59
+
60
+
61
+
BaseConnectionFactory
37
62
##################
38
63
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.
40
65
41
66
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:
42
67
@@ -45,6 +70,8 @@ to inherit from this class you need to pass in the underlying backend that you a
45
70
from valkey import Valkey
46
71
from valkey.connection import ConnectionPool
47
72
73
+
from django_valkey.base_pool import BaseConnectionFactory
0 commit comments