# 函数加载失败：库版本不匹配，期望 1 但实际为 2

- **ID:** `redis/function-load-version-mismatch`
- **领域:** redis
- **类别:** module_error
- **错误码:** `ERR`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

加载的 Redis 函数库版本号与服务器期望的版本不匹配，通常是由于 Redis 版本之间的 API 变更所致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.0 | active | — | — |
| 7.2 | active | — | — |
| 8.0-m3 | active | — | — |

## 解决方案

1. ```
   Upgrade the library to match the Redis server version by regenerating it with the correct API. Example: FUNCTION LOAD "#!lua name=mylib version=2 ..."
   ```
2. ```
   If the library was written for an older Redis version, rewrite it to use the current API, e.g., replace deprecated functions like redis.call with redis.pcall or adjust argument handling.
   ```
3. ```
   Delete the old library using FUNCTION DELETE and reload the correct version.
   ```

## 无效尝试

- **Force-load the library by ignoring the version check using a custom flag.** — Redis does not support ignoring version mismatches; loading will fail regardless. (95% 失败率)
- **Downgrade the Redis server to match the library version.** — This may introduce security vulnerabilities and break other features; it's not a scalable solution. (40% 失败率)
- **Manually edit the library file to change the version number.** — The version number is part of the library's serialization format; changing it can cause runtime errors or crashes. (70% 失败率)
