django-vcache 3.1.1__tar.gz → 3.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_vcache-3.1.1 → django_vcache-3.3.0}/Cargo.lock +17 -3
- {django_vcache-3.1.1 → django_vcache-3.3.0}/Cargo.toml +2 -2
- {django_vcache-3.1.1 → django_vcache-3.3.0}/PKG-INFO +25 -4
- {django_vcache-3.1.1 → django_vcache-3.3.0}/README.md +21 -3
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-core/Cargo.toml +7 -1
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-core/examples/bench.rs +1 -1
- django_vcache-3.3.0/crates/vcache-core/examples/kill_retry.rs +54 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-core/examples/standalone.rs +1 -1
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-core/src/connection.rs +477 -110
- django_vcache-3.3.0/crates/vcache-core/src/credential.rs +1002 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-core/src/lib.rs +5 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-pyo3/src/client.rs +199 -18
- django_vcache-3.3.0/crates/vcache-pyo3/src/credential.rs +212 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-pyo3/src/lib.rs +6 -1
- {django_vcache-3.1.1 → django_vcache-3.3.0}/django_vcache/backend.py +211 -2
- django_vcache-3.3.0/django_vcache/contrib/__init__.py +0 -0
- django_vcache-3.3.0/django_vcache/contrib/aws.py +351 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/pyproject.toml +7 -1
- {django_vcache-3.1.1 → django_vcache-3.3.0}/LICENSE +0 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-core/src/result.rs +0 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-core/src/runtime.rs +0 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-core/tests/runtime_provider.rs +0 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-pyo3/Cargo.toml +0 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-pyo3/src/async_bridge.rs +0 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/crates/vcache-pyo3/src/completion.rs +0 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/django_vcache/__init__.py +0 -0
- {django_vcache-3.1.1 → django_vcache-3.3.0}/django_vcache/exceptions.py +0 -0
|
@@ -714,7 +714,7 @@ dependencies = [
|
|
|
714
714
|
|
|
715
715
|
[[package]]
|
|
716
716
|
name = "rlib-link-test"
|
|
717
|
-
version = "3.
|
|
717
|
+
version = "3.3.0"
|
|
718
718
|
dependencies = [
|
|
719
719
|
"pyo3",
|
|
720
720
|
"vcache-pyo3",
|
|
@@ -960,6 +960,18 @@ dependencies = [
|
|
|
960
960
|
"tokio",
|
|
961
961
|
]
|
|
962
962
|
|
|
963
|
+
[[package]]
|
|
964
|
+
name = "tokio-stream"
|
|
965
|
+
version = "0.1.19"
|
|
966
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
967
|
+
checksum = "a3d06f0b082ba57c26b79407372e57cf2a1e28124f78e9479fe80322cf53420b"
|
|
968
|
+
dependencies = [
|
|
969
|
+
"futures-core",
|
|
970
|
+
"pin-project-lite",
|
|
971
|
+
"tokio",
|
|
972
|
+
"tokio-util",
|
|
973
|
+
]
|
|
974
|
+
|
|
963
975
|
[[package]]
|
|
964
976
|
name = "tokio-util"
|
|
965
977
|
version = "0.7.19"
|
|
@@ -1006,16 +1018,18 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
|
|
1006
1018
|
|
|
1007
1019
|
[[package]]
|
|
1008
1020
|
name = "vcache-core"
|
|
1009
|
-
version = "3.
|
|
1021
|
+
version = "3.3.0"
|
|
1010
1022
|
dependencies = [
|
|
1023
|
+
"arc-swap",
|
|
1011
1024
|
"redis",
|
|
1012
1025
|
"rustls",
|
|
1013
1026
|
"tokio",
|
|
1027
|
+
"tokio-stream",
|
|
1014
1028
|
]
|
|
1015
1029
|
|
|
1016
1030
|
[[package]]
|
|
1017
1031
|
name = "vcache-pyo3"
|
|
1018
|
-
version = "3.
|
|
1032
|
+
version = "3.3.0"
|
|
1019
1033
|
dependencies = [
|
|
1020
1034
|
"pyo3",
|
|
1021
1035
|
"redis",
|
|
@@ -3,12 +3,12 @@ resolver = "2"
|
|
|
3
3
|
members = ["crates/vcache-core", "crates/vcache-pyo3"]
|
|
4
4
|
|
|
5
5
|
[workspace.package]
|
|
6
|
-
version = "3.
|
|
6
|
+
version = "3.3.0"
|
|
7
7
|
edition = "2024"
|
|
8
8
|
|
|
9
9
|
[workspace.dependencies]
|
|
10
10
|
tokio = { version = "1", features = ["rt-multi-thread"] }
|
|
11
|
-
redis = { version = "1", features = ["tokio-comp", "connection-manager", "cluster", "cluster-async", "tokio-rustls-comp", "tls-rustls-insecure", "cache-aio"] }
|
|
11
|
+
redis = { version = "1", features = ["tokio-comp", "connection-manager", "cluster", "cluster-async", "tokio-rustls-comp", "tls-rustls-insecure", "cache-aio", "token-based-authentication"] }
|
|
12
12
|
rustls = { version = "0.23", features = ["ring"] }
|
|
13
13
|
# All current members are cdylibs that ship as Python extension modules;
|
|
14
14
|
# the `extension-module` feature skips libpython linking. If a future
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: django-vcache
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.3.0
|
|
4
4
|
Classifier: Development Status :: 5 - Production/Stable
|
|
5
5
|
Classifier: Framework :: Django
|
|
6
6
|
Classifier: Framework :: Django :: 5.0
|
|
@@ -15,11 +15,14 @@ Classifier: Programming Language :: Python :: 3
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.13
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
18
19
|
Classifier: Programming Language :: Rust
|
|
19
20
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
21
|
Requires-Dist: django>=5.0
|
|
21
22
|
Requires-Dist: ormsgpack
|
|
22
23
|
Requires-Dist: pyzstd ; python_full_version < '3.14'
|
|
24
|
+
Requires-Dist: botocore ; extra == 'aws'
|
|
25
|
+
Provides-Extra: aws
|
|
23
26
|
License-File: LICENSE
|
|
24
27
|
Summary: A specialized, lightweight Django cache backend for Valkey.
|
|
25
28
|
Author-email: David Burke <david@burkesoftware.com>
|
|
@@ -79,8 +82,8 @@ You can then use Django's cache framework as usual:
|
|
|
79
82
|
```python
|
|
80
83
|
from django.core.cache import cache
|
|
81
84
|
|
|
82
|
-
cache.set(
|
|
83
|
-
value = cache.get(
|
|
85
|
+
cache.set("my_key", "my_value", 30)
|
|
86
|
+
value = cache.get("my_key")
|
|
84
87
|
```
|
|
85
88
|
|
|
86
89
|
## API
|
|
@@ -189,6 +192,24 @@ export VALKEY_URL="sentinel://localhost:26379/mymaster/1"
|
|
|
189
192
|
|
|
190
193
|
The application will then be available at `http://localhost:8000`.
|
|
191
194
|
|
|
195
|
+
### Rotating credentials (AWS ElastiCache IAM auth)
|
|
196
|
+
|
|
197
|
+
For a cache that authenticates with a short-lived token instead of a fixed password, set `credential_provider` to a callable the driver consults and keeps current. ElastiCache IAM auth ships ready-made:
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
CACHES = {
|
|
201
|
+
"default": {
|
|
202
|
+
"BACKEND": "django_vcache.backend.ValkeyCache",
|
|
203
|
+
"LOCATION": "valkeys://app-iam-user@my-cache-abc123.serverless.use1.cache.amazonaws.com:6379/0",
|
|
204
|
+
"OPTIONS": {
|
|
205
|
+
"credential_provider": "django_vcache.contrib.aws.elasticache_iam_token",
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Install with `pip install "django-vcache[aws]"`. The driver mints a fresh token before each one expires and re-authenticates every live connection, which also resets ElastiCache's 12-hour IAM connection limit. Any issuer works: a provider is a plain function returning a password (optionally with `username` and `expires_at`). See the [configuration docs](https://vcache.glitchtip.com/configuration/#rotating-credentials).
|
|
212
|
+
|
|
192
213
|
### Using Valkey Cluster
|
|
193
214
|
|
|
194
215
|
To use `django-vcache` with a Valkey Cluster, set the `CLUSTER_MODE` option to `True` in your cache configuration. The `LOCATION` should point to one of the cluster's nodes; the driver will automatically discover the rest of the cluster nodes.
|
|
@@ -200,7 +221,7 @@ CACHES = {
|
|
|
200
221
|
"LOCATION": "valkey://your-cluster-node-1:6379/0",
|
|
201
222
|
"OPTIONS": {
|
|
202
223
|
"CLUSTER_MODE": True,
|
|
203
|
-
}
|
|
224
|
+
},
|
|
204
225
|
},
|
|
205
226
|
}
|
|
206
227
|
```
|
|
@@ -49,8 +49,8 @@ You can then use Django's cache framework as usual:
|
|
|
49
49
|
```python
|
|
50
50
|
from django.core.cache import cache
|
|
51
51
|
|
|
52
|
-
cache.set(
|
|
53
|
-
value = cache.get(
|
|
52
|
+
cache.set("my_key", "my_value", 30)
|
|
53
|
+
value = cache.get("my_key")
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
## API
|
|
@@ -159,6 +159,24 @@ export VALKEY_URL="sentinel://localhost:26379/mymaster/1"
|
|
|
159
159
|
|
|
160
160
|
The application will then be available at `http://localhost:8000`.
|
|
161
161
|
|
|
162
|
+
### Rotating credentials (AWS ElastiCache IAM auth)
|
|
163
|
+
|
|
164
|
+
For a cache that authenticates with a short-lived token instead of a fixed password, set `credential_provider` to a callable the driver consults and keeps current. ElastiCache IAM auth ships ready-made:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
CACHES = {
|
|
168
|
+
"default": {
|
|
169
|
+
"BACKEND": "django_vcache.backend.ValkeyCache",
|
|
170
|
+
"LOCATION": "valkeys://app-iam-user@my-cache-abc123.serverless.use1.cache.amazonaws.com:6379/0",
|
|
171
|
+
"OPTIONS": {
|
|
172
|
+
"credential_provider": "django_vcache.contrib.aws.elasticache_iam_token",
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Install with `pip install "django-vcache[aws]"`. The driver mints a fresh token before each one expires and re-authenticates every live connection, which also resets ElastiCache's 12-hour IAM connection limit. Any issuer works: a provider is a plain function returning a password (optionally with `username` and `expires_at`). See the [configuration docs](https://vcache.glitchtip.com/configuration/#rotating-credentials).
|
|
179
|
+
|
|
162
180
|
### Using Valkey Cluster
|
|
163
181
|
|
|
164
182
|
To use `django-vcache` with a Valkey Cluster, set the `CLUSTER_MODE` option to `True` in your cache configuration. The `LOCATION` should point to one of the cluster's nodes; the driver will automatically discover the rest of the cluster nodes.
|
|
@@ -170,7 +188,7 @@ CACHES = {
|
|
|
170
188
|
"LOCATION": "valkey://your-cluster-node-1:6379/0",
|
|
171
189
|
"OPTIONS": {
|
|
172
190
|
"CLUSTER_MODE": True,
|
|
173
|
-
}
|
|
191
|
+
},
|
|
174
192
|
},
|
|
175
193
|
}
|
|
176
194
|
```
|
|
@@ -11,7 +11,13 @@ name = "vcache_core"
|
|
|
11
11
|
[dependencies]
|
|
12
12
|
# "sync" is used directly (RwLock, OnceCell, Mutex) — declared explicitly
|
|
13
13
|
# rather than relying on feature unification through redis's tokio dep.
|
|
14
|
-
tokio = { workspace = true, features = ["sync"] }
|
|
14
|
+
tokio = { workspace = true, features = ["sync", "time"] }
|
|
15
|
+
# WatchStream adapts the credential watch channel to the Stream that redis's
|
|
16
|
+
# StreamingCredentialsProvider expects (see credential.rs).
|
|
17
|
+
tokio-stream = { version = "0.1", default-features = false, features = ["sync"] }
|
|
18
|
+
# Lock-free swap of the standalone ConnectionManager after a credential
|
|
19
|
+
# re-mint; already in the graph via redis-rs.
|
|
20
|
+
arc-swap = "1"
|
|
15
21
|
redis.workspace = true
|
|
16
22
|
rustls.workspace = true
|
|
17
23
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//! Manual check: does a server-side connection kill surface as an error, or
|
|
2
|
+
//! does the retry absorb it?
|
|
3
|
+
//!
|
|
4
|
+
//! Two modes, because they fail differently:
|
|
5
|
+
//!
|
|
6
|
+
//! * `MODE=get` — tight GET loop, so a kill usually lands with a command in
|
|
7
|
+
//! flight. This is the retried path.
|
|
8
|
+
//! * `MODE=blmove` — BLMOVE on an empty list, always in flight. This is the
|
|
9
|
+
//! shape of the reported ConnectionError, and is deliberately
|
|
10
|
+
//! NOT retried.
|
|
11
|
+
//!
|
|
12
|
+
//! Kill the connection from outside mid-run: `valkey-cli CLIENT KILL TYPE normal`
|
|
13
|
+
//!
|
|
14
|
+
//! VALKEY_URL=redis://127.0.0.1:6379/9 MODE=get cargo run -p vcache-core --example kill_retry
|
|
15
|
+
|
|
16
|
+
use std::time::{Duration, Instant};
|
|
17
|
+
use vcache_core::{connect_standard, get_runtime};
|
|
18
|
+
|
|
19
|
+
fn main() {
|
|
20
|
+
let url = std::env::var("VALKEY_URL").unwrap_or_else(|_| "redis://127.0.0.1:6379/9".into());
|
|
21
|
+
let retries = std::env::var("VCACHE_COMMAND_RETRIES").unwrap_or_else(|_| "default".into());
|
|
22
|
+
let mode = std::env::var("MODE").unwrap_or_else(|_| "get".into());
|
|
23
|
+
let secs: u64 = std::env::var("SECS")
|
|
24
|
+
.ok()
|
|
25
|
+
.and_then(|v| v.parse().ok())
|
|
26
|
+
.unwrap_or(6);
|
|
27
|
+
|
|
28
|
+
get_runtime().block_on(async move {
|
|
29
|
+
let mut conn = connect_standard(&url, None, None, None).await.expect("connect");
|
|
30
|
+
conn.set_bytes("kill_retry", b"before".to_vec(), Some(300))
|
|
31
|
+
.await
|
|
32
|
+
.expect("initial set");
|
|
33
|
+
println!("mode={mode} retries={retries}: running {secs}s");
|
|
34
|
+
|
|
35
|
+
let deadline = Instant::now() + Duration::from_secs(secs);
|
|
36
|
+
let (mut ops, mut failures) = (0u64, 0u64);
|
|
37
|
+
while Instant::now() < deadline {
|
|
38
|
+
ops += 1;
|
|
39
|
+
let result = if mode == "blmove" {
|
|
40
|
+
conn.blmove("kill_retry_src", "kill_retry_dst", "RIGHT", "LEFT", 1.0)
|
|
41
|
+
.await
|
|
42
|
+
.map(|_| ())
|
|
43
|
+
} else {
|
|
44
|
+
conn.get_bytes("kill_retry").await.map(|_| ())
|
|
45
|
+
};
|
|
46
|
+
if let Err(e) = result {
|
|
47
|
+
failures += 1;
|
|
48
|
+
println!(" op {ops}: FAILED: {e}");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
let _ = conn.del("kill_retry").await;
|
|
52
|
+
println!("mode={mode} retries={retries}: {failures} failed / {ops} ops");
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -10,7 +10,7 @@ use vcache_core::{connect_standard, get_runtime};
|
|
|
10
10
|
fn main() {
|
|
11
11
|
let url = std::env::var("VALKEY_URL").unwrap_or_else(|_| "redis://valkey:6379/1".into());
|
|
12
12
|
get_runtime().block_on(async move {
|
|
13
|
-
let mut conn = connect_standard(&url, None, None)
|
|
13
|
+
let mut conn = connect_standard(&url, None, None, None)
|
|
14
14
|
.await
|
|
15
15
|
.expect("connect failed");
|
|
16
16
|
conn.set_bytes("vcache_core_smoke", b"ok".to_vec(), Some(10))
|