Skip to main content

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 默认地址。

设计要点

  1. 幂等 append 用 Lua 脚本原子收口:一次往返内完成「查 Message.id 是否已存在 + 追加」, 多 worker 并发写同一 session 不会出现检查与写入之间的竞态;Message.id 为 NULL 时照写不去重。
  2. 快照存 hash:payload / status / saved_at 三字段,save_step 整包覆盖。
  3. 条件写 save_step_if:带期望状态的 CAS,approve / deny 跨进程竞态下只有一方能把挂起 run 从 pending 推进(RunCheckpoint 契约之外的扩展能力,SQLite / Postgres 同样提供)。
  4. key 带 hash tag {session_id} / {run_id}:同一会话/运行的多把 key 落同一 slot, Redis Cluster 下 Lua 脚本仍合法。
  5. 客户端懒连接: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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mainspring-session-redis 0.1.1
File Size Uploaded Provenance Actions
mainspring_session_redis-0.1.1.tar.gz 5.7 kB With provenance Details for mainspring_session_redis-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mainspring-session-redis 0.1.1
File Interpreter ABI Platform Actions
mainspring_session_redis-0.1.1-py3-none-any.whl Python 3 none any Details for mainspring_session_redis-0.1.1-py3-none-any.whl

Total release size: 12.8 kB

Release files / mainspring_session_redis-0.1.1.tar.gz

Download URL mainspring_session_redis-0.1.1.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2c642ad6d9c7cd744dc599f26bb278d144234ad4aa7aaab65a8c2b6d3d67ec43
BLAKE2b-256 checksum
How to use checksums
ea195b2fe6edc97ea37d522ace0419ba4477baa20f4bc8c9b2bcfb671ad73806
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 log

Release files / mainspring_session_redis-0.1.1-py3-none-any.whl

Download URL mainspring_session_redis-0.1.1-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d734979c9aba32a31771433169bf1041b6307d88d02ac2641e94375b4f7b5539
BLAKE2b-256 checksum
How to use checksums
5edd96ec2697e39dd9f20cc4aea6e8006b48e7fc327b945b4a7c2ff0435c7811
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 log

Security for mainspring-session-redis 0.1.1

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.

Select from 2 files

Attestation for mainspring_session_redis-0.1.1.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 log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page