Skip to main content

Crate naidempotency_redis

Crate naidempotency_redis 

Source
Expand description

幂等 store 的 Redis 后端。

实现 naidempotency::IdempotencyStore,response-cache 语义(:非资金/幂等重放场景; 资金强幂等应落业务 DB 唯一键同事务,见 naidempotency-mysql)。

  • begin:SET key <inflight> NX PX <ttl> 原子占位——成功=首次;已存在则 GET 现有值裁决 重放/并发/指纹冲突。in-flight 键带较短 TTL,进程崩溃后自动过期使重试可继续。
  • complete:二进制 EVAL 原子 check-and-set——仅当现值仍 in-flight 才覆写为 completed(保留 原 fingerprint),带较长 TTL 作重放窗口。避免 GET-then-SET 的覆写竞态。

所有键经 RedisClient::execute_raw 直发(不走 nadis namespace 前缀,SET/GET/EVAL 完全一致); 底层错误一律脱敏为 IdempotencyError。

值编码(二进制,Redis 值二进制安全):in-flight 为 [state:1][fingerprint:32][lease:16];completed 保存指纹与 status/header/body,响应上限由调用方约束。

Structs§

RedisIdempotencyStore
Redis 幂等 store。持注入的 RedisClient;可配 in-flight / completed 两档 TTL。