command
Version:
v0.6.0
Opens a new window with list of versions in this module.
Published: Aug 8, 2026
License: Apache-2.0
Opens a new window with license information.
Imports: 5
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
Documentation
¶
txn 示例:跨域原子事务——扣钱包 + 写存档,任一失败全回滚。
演示 pkg/txn 的两阶段提交:用 staging(副本)视图操作,Prepare 暂存、
Commit 落库、Rollback 丢弃。这里用内存快照模拟:Prepare 前深拷贝主库,
Commit 把 staging swap 成主库,Rollback 丢弃 staging。
场景:购买道具——扣金币 + 写背包存档。扣费后存档若失败,金币必须退还。
跑:go run ./examples/txn
Source Files
¶
Click to show internal directories.
Click to hide internal directories.