# redis.exceptions.ResponseError: Error running script (call to f_abcdef123456): @user_script:1: WRONGTYPE Operation against a key holding the wrong kind of value

- **ID:** `database/redis-lua-script-execution-error`
- **Domain:** database
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

A Redis Lua script attempted to perform an operation (e.g., LPUSH on a string key) that is incompatible with the data type stored at the key, causing a WRONGTYPE error.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Redis 7.2.4 | active | — | — |
| Redis 6.2.14 | active | — | — |
| Redis Stack 7.2.0 | active | — | — |

## Workarounds

1. **Identify the offending key by running: TYPE <key> in redis-cli. Then either delete the key (DEL <key>) or modify the script to handle the existing type (e.g., use EXISTS to check type before operations).** (90% success)
   ```
   Identify the offending key by running: TYPE <key> in redis-cli. Then either delete the key (DEL <key>) or modify the script to handle the existing type (e.g., use EXISTS to check type before operations).
   ```
2. **Update the Lua script to use TYPE command to check the key's type before performing operations, and return an error or handle gracefully: local keyType = redis.call('TYPE', KEYS[1]); if keyType ~= 'list' then return redis.error_reply('Expected list, got ' .. keyType) end** (85% success)
   ```
   Update the Lua script to use TYPE command to check the key's type before performing operations, and return an error or handle gracefully: local keyType = redis.call('TYPE', KEYS[1]); if keyType ~= 'list' then return redis.error_reply('Expected list, got ' .. keyType) end
   ```
3. **If the key should be a list but is currently a string, convert it by deleting and recreating: DEL mykey; LPUSH mykey value1 value2; then retry the script.** (80% success)
   ```
   If the key should be a list but is currently a string, convert it by deleting and recreating: DEL mykey; LPUSH mykey value1 value2; then retry the script.
   ```

## Dead Ends

- **Flushing all keys with FLUSHALL to clear the data type mismatch** — This deletes all data, which is an extreme measure; the script will still fail if the same key is recreated with the wrong type. (95% fail)
- **Ignoring the error and retrying the script** — The error is deterministic; retrying without fixing the key type will produce the same error every time. (100% fail)
- **Using EVAL instead of EVALSHA to force script recompilation** — The error is not due to script caching; it's a runtime type mismatch. EVAL will still fail with the same error. (90% fail)
