基础设施
限流 / 熔断 / 重试 / 缓存 / 分布式锁
在线 Playground
在浏览器中直接体验本页相关 API,无需本地安装 Go 环境。
基础设施
生产环境常用的弹性组件,均可独立 go get,按需组合。
模块
限流器
令牌桶 / 并发控制 / Redis 分布式
熔断器
失败率熔断 / Half-Open 试探
重试
指数退避 / 固定间隔 / 熔断集成
缓存
LRU / Redis / 多级缓存
分布式锁
Redis / Etcd / RedLock
布隆过滤器
内存 / Redis 布隆过滤器
事件总线
进程内 pub/sub
任务队列
内存任务队列
调度器
Cron 分布式调度
推荐组合
对外部 API(如 relay 调用上游 LLM):
retry(瞬时错误) + circuitbreaker(级联保护) + limiter(保护自身)对热点数据:
cache/lru(L1) + cache/redis(L2) + lock/redis(防击穿)relay 集成示例
import (
"time"
"github.com/LingByte/ling-base/common/circuitbreaker"
"github.com/LingByte/ling-base/common/retry"
"github.com/LingByte/ling-base/relay"
)
cb := circuitbreaker.New(circuitbreaker.Config{
FailureThreshold: 0.5,
MinRequests: 10,
RecoveryTimeout: 30 * time.Second,
})
client := relay.New(
relay.WithProvider(provider),
relay.WithRetry(
retry.WithMaxAttempts(3),
retry.WithExponentialBackoff(100*time.Millisecond, 2*time.Second, 2.0, true),
),
relay.WithCircuitBreaker(cb),
)相关模块
common/bloom(布隆过滤器)、common/eventbus(进程内事件总线)等见 通用工具 完整列表。