ERR WATCH inside MULTI is not allowed: WATCH inside MULTI is not allowed
RedisWhat does it mean?
WATCH was sent while inside an open MULTI block. For optimistic locking, WATCH must put keys under watch BEFORE the transaction starts; if called after MULTI it is rejected. The error does not abort the transaction; only WATCH fails and nothing is watched.
Why does it happen?
WATCH and MULTI written in reverse order in code (MULTI first, then WATCH); calling WATCH inside the client library's pipeline/transaction wrapper; or using a pooled connection left in MULTI state. In this case EXEC runs even if the keys expected to be watched have changed; the expected conflict protection does not kick in.
How to fix it
Correct order: WATCH key -> (read values) -> MULTI -> commands -> EXEC. If EXEC returns nil, a watched key changed; retry the operation from the start. Use the client library's WATCH/transaction API (e.g., watch + pipeline helpers). Note: pub/sub commands such as SUBSCRIBE are not rejected inside MULTI; they are queued and the connection switches to subscribe mode after EXEC; this is also not recommended, use a dedicated connection for pub/sub.
More from this engine
- ERR bit offset is not an integer or out of rangeBit offset is not an integer or out of range
- ERR Protocol error: invalid multibulk lengthProtocol error: invalid multibulk length
- ERR Number of keys can't be greater than number of argsEVAL/EVALSHA: numkeys exceeds argument count
- ERR WAIT cannot be used with replica instancesWAIT cannot be used with replica instances
- ERR Background append only file rewriting already in progressAOF rewrite already in progress
- IOERR error or timeout reading from target instanceMIGRATE: I/O error or timeout to target
- ERR Error compiling script (new function)Error compiling Lua script