{"record":{"id":"5ee52de565c02c5c","repo":"redis/redis-py","slug":"monitor-failed-response","errorCode":null,"errorMessage":"MONITOR failed: {response}","messagePattern":"MONITOR failed: (.+?)","errorType":"exception","errorClass":"RedisError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/client.py","lineNumber":1092,"sourceCode":"\n    monitor_re = re.compile(r\"\\[(\\d+) (.*?)\\] (.*)\")\n    command_re = re.compile(r'\"(.*?)(?<!\\\\)\"')\n\n    def __init__(self, connection_pool: ConnectionPool):\n        self.connection_pool = connection_pool\n        self.connection: Optional[Connection] = None\n\n    async def connect(self):\n        if self.connection is None:\n            self.connection = await self.connection_pool.get_connection()\n\n    async def __aenter__(self):\n        await self.connect()\n        await self.connection.send_command(\"MONITOR\")\n        # check that monitor returns 'OK', but don't return it to user\n        response = await self.connection.read_response()\n        if not bool_ok(response):\n            raise RedisError(f\"MONITOR failed: {response}\")\n        return self\n\n    async def __aexit__(self, *args):\n        await self.connection.disconnect()\n        await self.connection_pool.release(self.connection)\n\n    async def next_command(self) -> MonitorCommandInfo:\n        \"\"\"Parse the response from a monitor command\"\"\"\n        await self.connect()\n        response = await self.connection.read_response()\n        if isinstance(response, bytes):\n            response = self.connection.encoder.decode(response, force=True)\n        command_time, command_data = response.split(\" \", 1)\n        m = self.monitor_re.match(command_data)\n        db_id, client_info, command = m.groups()\n        command = \" \".join(self.command_re.findall(command))\n        # Redis escapes double quotes because each piece of the command\n        # string is surrounded by double quotes. We don't have that","sourceCodeStart":1074,"sourceCodeEnd":1110,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/client.py#L1074-L1110","documentation":"Raised inside Monitor.__aenter__ after sending MONITOR and reading the server reply: if the reply does not pass the bool_ok check (i.e. it is not the simple-string \"OK\"), the library treats MONITOR setup as failed and aborts. The f-string interpolates the raw response so the actual server reply is visible. This is a hard failure that prevents the monitor context from being entered.","triggerScenarios":"Calling async with redis.asyncio.Redis(...).monitor() as m: when the server returns a non-OK reply to MONITOR — e.g. the connected user lacks the admin permission required to run MONITOR, the server returned an -ERR / -BUSY /moved, or a RESP3 push/redirect was misread as the MONITOR acknowledgment.","commonSituations":"Using a least-privilege ACL user that lacks the +@admin or MONITOR permission; running MONITOR against Redis Cloud / a managed instance where it is disabled; a failover happening exactly as MONITOR is issued so the reply is an error.","solutions":["Grant the connecting user permission to run MONITOR (ACL: +@admin or +monitor).","Check the interpolated response string — if it is an ACL error, fix credentials; if it is MOVED/CLUSTERDOWN, you are hitting a cluster where MONITOR must target a specific node.","Avoid MONITOR in production; use it only for local debugging."],"exampleFix":"// before\nasync with client.monitor() as m:\n    ...\n// after\n# ensure the ACL user can run MONITOR\n# redis-cli ACL SETUSER monitor_user on >pass +monitor on ~*\nasync with client.monitor() as m:\n    ...","handlingStrategy":"try-catch","validationCode":"# Before opening a monitor, verify the user can run MONITOR:\ninfo = await client.acl_whoami()  # or check ACL GETUSER\n# There is no pure-client precondition for MONITOR success; rely on ACL setup.","typeGuard":null,"tryCatchPattern":"try:\n    async with client.monitor() as m:\n        ...\nexcept RedisError as e:\n    if 'MONITOR failed' in str(e):\n        # log and degrade; MONITOR unavailable for this user/env\n        ...","preventionTips":["Grant the connecting ACL user +monitor (or +@admin).","Use MONITOR only for local debugging, never in the hot path."],"tags":["monitor","acl","permissions","protocol"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}