# ERR 未知子命令或参数数量错误：'SLOWLOG'

- **ID:** `redis/err-unknown-subcommand`
- **领域:** redis
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

Redis 收到了无效的子命令或参数数量错误，通常是由于客户端库版本不匹配或拼写错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Redis 6.2 | active | — | — |
| Redis 7.0 | active | — | — |
| Redis 7.2 | active | — | — |
| redis-py 4.5.0 | active | — | — |
| redis-py 5.0.0 | active | — | — |

## 解决方案

1. ```
   Update the client library to a version compatible with your Redis server version. For example, in Python using redis-py, run: `pip install redis>=5.0.0`
   ```
2. ```
   Verify the correct subcommand syntax by checking the Redis documentation. For SLOWLOG, use: `SLOWLOG GET 10` instead of `SLOWLOG GETALL`.
   ```
3. ```
   In the client code, wrap the slow log command in a try-except and fall back to a known working subcommand. Example in Python: `try: r.execute_command('SLOWLOG', 'GET', 10) except redis.exceptions.ResponseError: r.execute_command('SLOWLOG', 'LEN')`
   ```

## 无效尝试

- **** — Restarting does not change the client command that triggered the error. (90% 失败率)
- **** — The client library still sends the same malformed command. (70% 失败率)
- **** — This is a workaround that sacrifices monitoring capabilities. (60% 失败率)
