# ERR Function load failed: library version mismatch, expected 1 but got 2

- **ID:** `redis/function-load-version-mismatch`
- **Domain:** redis
- **Category:** module_error
- **Error Code:** `ERR`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The Redis Functions library being loaded has a version number that does not match the version expected by the server, likely due to API changes between Redis versions.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.0 | active | — | — |
| 7.2 | active | — | — |
| 8.0-m3 | active | — | — |

## Workarounds

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 ..."** (90% success)
   ```
   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.** (85% success)
   ```
   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.** (95% success)
   ```
   Delete the old library using FUNCTION DELETE and reload the correct version.
   ```

## Dead Ends

- **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% fail)
- **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% fail)
- **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% fail)
