示例工程 32-openresty-and-redis

32-openresty-and-redis/03-redis-rate-limit/README.md

markdown · 0.6 KB

# 03 · redis-rate-limit
 
**演示**:`INCR` + `EXPIRE` 的固定窗口限流,`redis.call` 用 stub。
**运行时**:`lua54`(stub;真实 Redis 为 🖐)。
**运行**:
 
```sh
.tools/bin/lua54 scripts/run-example.lua examples/32-openresty-and-redis/03-redis-rate-limit
.tools/bin/lua54 scripts/test-example.lua examples/32-openresty-and-redis/03-redis-rate-limit
```
 
**预期输出**(lua 5.4.9 / macOS arm64):
 
```text
first=true second=true third=false
```
 
**看点**:Redis 脚本原子执行;`KEYS` 必须显式传,不能拼字符串。
**注意**:🖐 真实 `EVAL` 里没有 `os.time`/`io`,脚本要可重放。