vault backup: 2026-05-31 21:15:22

This commit is contained in:
2026-05-31 21:15:22 +08:00
parent 42f0507747
commit 420744ce9d
2 changed files with 358 additions and 0 deletions
+14
View File
@@ -91,6 +91,19 @@ key := fmt.Sprintf("rate:limit:%s:%d", userId, windowStart)
这段代码短小精悍,看起来已经够用了。但它有一个**隐蔽的边界问题**。
> [!info]- 💡 Redis Key 中的 `id` 是什么?
>
> 文中的 `id` 不是固定指某个业务字段,而是**限流维度的路由标识(identifier)**——你想限制谁,它就等于谁的唯一标识。常见取:
>
> | 限流维度 | `id` 实际取值 | Key 示例 |
> |---------|-------------|----------|
> | **用户级**(L2) | 用户 ID / 账号 ID | `rate:limit:user_10086:1717132800` |
> | **IP 级**(L1) | 客户端 IP | `rate:limit:192.168.1.42:1717132800` |
> | **接口级**(L3) | 接口路径或名称 | `rate:limit:/api/register:1717132800` |
> | **API Key 级** | 客户端凭证 | `rate:limit:app_key_xxx:1717132800` |
>
> 生产环境中通常是**多级组合**:例如同时用 `userId + endpoint` 作为复合 Key,做到细粒度控制。
### 1.2 边界突发:窗口的"双杀"效应
> [!warning]- ⚠️ 先看一个具体例子
@@ -437,5 +450,6 @@ flowchart LR
## 关联笔记
- [[Lua脚本]] — Redis Lua 脚本基础概念与使用模式
- [[02-服务治理/06-容错模式]] — 限流是容错体系的第三层防线
- [[02-服务治理/01-API网关]] — API 网关层的限流插件集成