cache

command
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

演示: Redis 接入 —— Wire 装配 cache + snowflake, 覆盖基础命令封装 / 分布式锁 / 延迟队列。

需要本地 redis(唯一有外部依赖的 demo):

docker run -d -p 6379:6379 redis:latest

运行:

cd example/cache && go run .

访问(另开终端):

下单(10s 内不支付将被延迟队列自动关闭):
  curl -X POST http://127.0.0.1:8083/api/v1/orders -H "Content-Type: application/json" -d '{"item":"phone"}'
查询订单:
  curl http://127.0.0.1:8083/api/v1/orders/{id}
支付(10s 内调用则订单存活, 超时后返回"订单已关闭"):
  curl -X POST http://127.0.0.1:8083/api/v1/orders/{id}/pay
秒杀抢购(分布式锁防重复提交 + 原子扣减防超卖):
  curl -X POST http://127.0.0.1:8083/api/v1/seckill -H "Content-Type: application/json" -d '{"user":"alice"}'

分工演示: cache / snowflake 走 Wire 装配(一行一个), 延迟队列是业务长驻组件, 在 Init 钩子创建、Close 钩子停止 —— 这是"基础组件 vs 业务组件"的标准接法。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL