mainspring-session-redis
Redis 会话后端 + RunCheckpoint 实现(T4-3)。实现 core 的两个 Protocol,与 SQLite 外挂共用
同一套接口契约测试(tests/test_session_backends.py),换后端只改 yaml。
用法
from mainspring_session_redis import open_redis, backend_factory
store, checkpoint = open_redis("redis://:mainspring@127.0.0.1:6379/0")
await store.append("s1", [Message(id="m1", role="user", content="你好")])
yaml 装配(core 不反向依赖外挂:工厂由调用方注入):
session:
backend: redis
url: redis://:mainspring@127.0.0.1:6379/0
runner = build_runner(config, backends={"redis": backend_factory}, checkpoint=checkpoint)
url 缺省取 MAINSPRING_SESSION_REDIS_URL,再缺省用 compose 默认地址。
设计要点
- 幂等 append 用 Lua 脚本原子收口:一次往返内完成「查 Message.id 是否已存在 + 追加」,
多 worker 并发写同一 session 不会出现检查与写入之间的竞态;
Message.id为 NULL 时照写不去重。 - 快照存 hash:
payload / status / saved_at三字段,save_step整包覆盖。 - 条件写
save_step_if:带期望状态的 CAS,approve / deny 跨进程竞态下只有一方能把挂起 run 从pending推进(RunCheckpoint 契约之外的扩展能力,SQLite / Postgres 同样提供)。 - key 带 hash tag
{session_id}/{run_id}:同一会话/运行的多把 key 落同一 slot, Redis Cluster 下 Lua 脚本仍合法。 - 客户端懒连接:yaml 装配阶段不依赖 Redis 在线;
aclose()关闭共享客户端。
验收
docker compose up -d redis后跑pytest tests/test_session_backends.py -k redis;- 覆盖:append 幂等 / NULL 不去重 / 会话隔离与删除 / 快照八要素 roundtrip / 覆盖写 / 并发双写 / 条件写单赢家;
- core 零反向依赖由 import-linter 守护。
Metadata
Release files for mainspring-session-redis 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mainspring_session_redis-0.1.0.tar.gz | 5.7 kB | With provenance | Details for mainspring_session_redis-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mainspring_session_redis-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mainspring_session_redis-0.1.0-py3-none-any.whl |
Total release size: 12.8 kB
Release files / mainspring_session_redis-0.1.0.tar.gz
| Download URL | mainspring_session_redis-0.1.0.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de8bbb78937387620ddedefd8aab01a069030315dbf90b1f65f22cc693cbebf2
|
|
BLAKE2b-256 checksum How to use checksums |
9f97bbd69a37f6c76b0a7fbf288c9ca368370a0793f981f82883861b8cd93498
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / mainspring_session_redis-0.1.0-py3-none-any.whl
| Download URL | mainspring_session_redis-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
733e83bd25e03004857a5ff9d5b39dfca7ec74f143b66ff5baa7b6121b14fd44
|
|
BLAKE2b-256 checksum How to use checksums |
fb74093dfa49515b413c8557e33e55c2527c83537587a9106f6c3bbf37ee59e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logSecurity for mainspring-session-redis 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mainspring_session_redis-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.