Skip to content

Commit 0cbc31a

Browse files
committed
migrate docs to mkdocs
1 parent fe6a400 commit 0cbc31a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1647
-1849
lines changed

.readthedocs.yaml

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
version: "2"
1+
version: 2
22

33
build:
44
os: "ubuntu-lts-latest"
55
tools:
6-
python: "3.12"
6+
python: "3.13"
77

88
jobs:
99
pre_build:
10-
- pip install .
11-
- pip install sphinx-pdj-theme
12-
sphinx:
13-
configuration: docs/source/conf.py
10+
- pip install mkdocs-material mkdocs-awesome-nav
11+
mkdocs:
12+
configuration: mkdocs.yml
1413

1514
formats:
1615
- pdf

CHANGES.rst CHANGES.md

File renamed without changes.

docs/.nav.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sort:
2+
sections: first
3+
4+
nav:
5+
- installation.md
6+
7+
- configure
8+
- async
9+
- commands
10+
11+
- migration_from_django_redis.md
12+
- customize.md
13+
- changes.md

docs/Makefile

-20
This file was deleted.

docs/async/.nav.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
nav:
2+
- configurations.md
3+
- advanced_configurations.md
4+
- async_commands.md
5+
- access_to_pool.md

docs/async/access_to_pool.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Access the connection pool
2+
3+
you can get the connection pool using this code:
4+
5+
```python
6+
from django_valkey.async_cache import get_valkey_connection
7+
8+
async def get_connection():
9+
r = await get_valkey_connection("default") # use the name defined in ``CACHES`` settings
10+
connection_pool = r.connection_pool
11+
print(f"created connections so far: {connection_pool._created_connections}")
12+
```
13+
14+
this will verify how many connections the pool has opened.

docs/async/advanced_configurations.md

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Advanced Async Configuration
2+
3+
most of the subject discussed in [Advanced configuration](../configure/advanced_configurations.md) apply to async mode as well, just don't use a sync client :)
4+
5+
also all the compressor details we talked about in [Compressor support](../configure/compressors.md) work as is in async mode
6+
7+
**Important**: the async clients are not compatible with django's cache middleware.
8+
if you need those middlewares, consider using a sync client or implement a new middleware
9+
10+
## Clients
11+
12+
We have three async client, `AsyncDefaultClient`, available in `django_valkey.async_cache.client.default`, `AsyncHerdClient` available in `django_valkey.async_cache.client.herd` and `AsyncSentinelClient` at `django_valkey.async_cache.client.sentinel`.
13+
the default client can also be used with sentinels, as we'll discuss later.
14+
15+
note that all clients are imported and available at `django_valkey.async_cache.client`
16+
17+
### Default client
18+
19+
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:
20+
21+
```python
22+
CACHES = {
23+
"async": {
24+
"BACKEND": "path.to.backend",
25+
"LOCATION": [
26+
"valkey://user:[email protected]:6379",
27+
]
28+
"OPTIONS": {
29+
"CLIENT_CLASS": "django_valkey.async_cache.client.AsyncDefaultClient",
30+
}
31+
}
32+
}
33+
```
34+
35+
or you can replace the client with your own like that.
36+
37+
### Sentinel Client
38+
39+
to support sentinels, django_valkey comes with a client and a connection factory, technically you don't need the connection factory, but it provides you with some nice features.
40+
a dedicated page on sentinel client has been written in [Sentinel configuration](../configure/sentinel_configurations.md), tho that is for the sync version, the principle is the same.
41+
42+
the connection factory is at `django_valkey.async_cache.pool.AsyncSentinelConnectionFactory`.
43+
44+
to configure the async sentinel client you can write your settings like this:
45+
46+
```python
47+
SENTINELS = [
48+
("127.0.0.1", 26379), # a list of (host name, port) tuples.
49+
]
50+
51+
CACHES = {
52+
"default": {
53+
"BACKEND": "django_valkey.async_cache.cache.AsyncValkeyCache",
54+
"LOCATION": "valkey://service_name/db",
55+
"OPTIONS": {
56+
"CLIENT_CLASS": "django_valkey.client.SentinelClient",
57+
"SENTINELS": SENTINELS,
58+
59+
# optional
60+
"SENTINEL_KWARGS": {}
61+
}
62+
}
63+
}
64+
```
65+
66+
*note*: the sentinel client uses the sentinel connection factory by default, you can change it by setting `DJANGO_VALKEY_CONNECTION_FACTORY` in your django settings or `CONNECTION_FACTORY` in your `CACHES` OPTIONS.
67+
68+
### Herd client
69+
70+
the herd client needs to be configured, but it's as simple as this:
71+
72+
```python
73+
CACHES = {
74+
"default": {
75+
"BACKEND": "django_valkey.async_cache.cache.AsyncValkeyCache",
76+
"LOCATION": ["valkey://127.0.0.1:6379"],
77+
"OPTIONS": {
78+
"CLIENT_CLASS": "django_valkey.async_cache.client.AsyncHerdClient",
79+
}
80+
}
81+
}
82+
```
83+
84+
## Connection Factory
85+
86+
django_valkey's async library comes with two connection factories, `AsyncConnectionFactory` for general uses and `AsyncSentinelConnectionFactory` for sentinel uses.
87+
88+
the default connection factory is `AsyncConnectionFactory`, so if you are using a sentinel server you should configure your caches like this:
89+
90+
```python
91+
CACHES = {
92+
"async": {
93+
# ...
94+
"OPTIONS": {
95+
"CONNECTION_FACTORY": "django_valkey.async_cache.pool.AsyncSentinelConnectionFactory"
96+
}
97+
}
98+
}
99+
100+
CACHE_HERD_TIMEOUT = 20 # if not set, it's default to 60
101+
```
102+
103+
or set it as the global connection factory like this:
104+
105+
```python
106+
DJANGO_VALKEY_CONNECTION_FACTORY = "django_valkey.async_cache.client.default.AsyncDefaultClient"
107+
```
108+
109+
note that `"CONNECTION_FACTORY"` overrides `DJANGO_VALKEY_CONNECTION_FACTORY` for the specified server.
110+
111+
if you want to use another factory you can use the same code with the path to your class.
112+

docs/async/async_commands.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Valkey native commands
2+
3+
you can directly work with valkey using django's cache object.
4+
5+
most subject discussed in [valkey commands](../commands/valkey_native_commands.md) also applies here.
6+
7+
```pycon
8+
>>> from django.core.cache import cache
9+
10+
>>> await cache.aget("foo")
11+
```
12+
13+
the method names are the same as the sync ones discussed in [valkey commands](../commands/valkey_native_commands.md), and the API is almost the same.
14+
15+
the only difference is that the async backend returns a coroutine or async generator depending on the method, and you should `await` it or iterate over it.
16+
17+
```python
18+
import contextlib
19+
from django.core.cache import cache
20+
21+
async with contextlib.aclosing(cache.aiter_keys("foo*")) as keys:
22+
async for k in keys:
23+
print(k)
24+
```
25+
26+
another thing to notice is that the method names are the same as the sync ones: `await get()` or `get()`.
27+
but if you want to be explicit the same methods are also available with a `a` prepended to them: `await aget()`.
28+
this goes for all public methods of the async client.

docs/async/configurations.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Configure The Async Client
2+
3+
**Warning**: as of django 5.2, async support for cache backends is flaky, if you decide to use the async backends do so with caution.
4+
5+
**Important**: the async client is not compatible with django's cache middlewares.
6+
if you need the middlewares, consider using the sync client or implement a new middleware.
7+
8+
there are two async clients available, a normal client and a herd client.
9+
10+
## Default client
11+
12+
to setup the async client you can configure your settings file to look like this:
13+
14+
```python
15+
CACHES = {
16+
"default": {
17+
"BACKEND": "django_valkey.async_cache.cache.AsyncValkeyCache",
18+
"LOCATION": "valkey://127.0.0.1:6379",
19+
"OPTIONS": {...},
20+
},
21+
}
22+
```
23+
24+
take a look at [Configure the database URL](../configure/advanced_configurations.md#configure-the-database-url) to see other ways to write the URL.
25+
And that's it, the backend defaults to use AsyncDefaultClient as client interface, AsyncConnectionFactory as connection factory and valkey-py's async client.
26+
27+
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 [Advanced Configurations](../configure/advanced_configurations.md).
28+
29+
## Herd client
30+
31+
to set up herd client configure your settings like this:
32+
33+
```python
34+
CACHES = {
35+
"default": {
36+
"BACKEND": "django_valkey.async_cache.caches.AsyncValkeyCache",
37+
"LOCATION": "valkey://127.0.0.1:6379",
38+
"OPTIONS": {
39+
"CLIENT_CLASS": "django_valkey.async_cache.client.AsyncHerdClient",
40+
},
41+
},
42+
}
43+
```
44+
45+
for a more specified guide look at [Advanced Async Configuration](advanced_configurations.md).

docs/changes.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Change Log
2+
--8<-- "./CHANGES.md"

docs/commands/.nav.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nav:
2+
- connection_pool_commands.md
3+
- valkey_native_commands.md
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Access the connection pool
2+
3+
you can get the connection pool using this code:
4+
5+
```python
6+
from django_valkey import get_valkey_connection
7+
8+
r = get_valkey_connection("default") # use the name defined in ``CACHES`` settings
9+
connection_pool = r.connection_pool
10+
print(f"created connections so far: {connection_pool._created_connections}")
11+
```
12+
13+
this will verify how many connections the pool has opened.

0 commit comments

Comments
 (0)