{"id":"21429cfb89b883f8","repo":"redis/redis-py","slug":"xread-max-count-must-be-a-positive-integer","errorCode":null,"errorMessage":"XREAD max_count must be a positive integer","messagePattern":"XREAD max_count must be a positive integer","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":7918,"sourceCode":"                  may still be returned. Must be a positive integer. Requires\n                  Redis >= 8.10.0.\n\n        For more information, see https://redis.io/commands/xread\n        \"\"\"\n        pieces = []\n        if block is not None:\n            if not isinstance(block, int) or block < 0:\n                raise DataError(\"XREAD block must be a non-negative integer\")\n            pieces.append(b\"BLOCK\")\n            pieces.append(str(block))\n        if count is not None:\n            if not isinstance(count, int) or count < 1:\n                raise DataError(\"XREAD count must be a positive integer\")\n            pieces.append(b\"COUNT\")\n            pieces.append(str(count))\n        if max_count is not None:\n            if not isinstance(max_count, int) or max_count < 1:\n                raise DataError(\"XREAD max_count must be a positive integer\")\n            if count is not None and max_count < count:\n                raise DataError(\n                    \"XREAD max_count must be greater than or equal to count\"\n                )\n            pieces.append(b\"MAXCOUNT\")\n            pieces.append(str(max_count))\n        if max_size is not None:\n            if not isinstance(max_size, int) or max_size < 1:\n                raise DataError(\"XREAD max_size must be a positive integer\")\n            pieces.append(b\"MAXSIZE\")\n            pieces.append(str(max_size))\n        if not isinstance(streams, dict) or len(streams) == 0:\n            raise DataError(\"XREAD streams must be a non empty dict\")\n        pieces.append(b\"STREAMS\")\n        keys, values = zip(*streams.items())\n        pieces.extend(keys)\n        pieces.extend(values)\n        response = self.execute_command(\"XREAD\", *pieces, keys=keys)","sourceCodeStart":7900,"sourceCodeEnd":7936,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L7900-L7936","documentation":"Raised by xread() when the max_count argument is not an int or is less than 1. max_count is a cumulative cap across all streams (distinct from per-stream count) and requires Redis >= 8.10.0. If both count and max_count are set, max_count must be >= count (a separate DataError is raised otherwise).","triggerScenarios":"Call client.xread(streams, max_count=...) with a non-int, zero, or negative value. Also requires a Redis server >= 8.10.0 to be meaningful at runtime; older servers will reject the MAXCOUNT option.","commonSituations":"Assuming max_count is supported on an older Redis (server then returns a syntax error); passing the same float-typed variable for both count and max_count; feeding a string from config.","solutions":["Pass an int >= 1 for max_count.","Verify Redis server version >= 8.10.0 before using MAXCOUNT/MAXSIZE.","Ensure max_count >= count when both are set.","Coerce: max_count = int(max_count) if max_count else None."],"exampleFix":"// before\nclient.xread({\"s\": \"0\"}, count=10, max_count=\"50\")\n// after\nclient.xread({\"s\": \"0\"}, count=10, max_count=50)","handlingStrategy":"validation","validationCode":"def normalize_max_count(v, count=None):\n    if v is None:\n        return None\n    if not isinstance(v, int) or isinstance(v, bool):\n        raise TypeError(f\"max_count must be int, got {type(v)}\")\n    if v < 1:\n        raise ValueError(f\"max_count must be >= 1, got {v}\")\n    if count is not None and v < count:\n        raise ValueError(f\"max_count ({v}) must be >= count ({count})\")\n    return v\n\n# also confirm server version supports MAXCOUNT (Redis >= 8.10.0)\ninfo = client.info(\"server\")\nif tuple(int(x) for x in info[\"redis_version\"].split(\".\")[:2]) < (8, 10):\n    raise RuntimeError(\"MAXCOUNT requires Redis >= 8.10.0\")","typeGuard":"def is_positive_int(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and v >= 1","tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    client.xread({\"s\": \"0\"}, count=count, max_count=max_count)\nexcept DataError as e:\n    if \"XREAD max_count\" in str(e) and \"greater than\" not in str(e):\n        client.xread({\"s\": \"0\"}, count=count, max_count=int(max_count))\n    else:\n        raise","preventionTips":["Gate MAXCOUNT/MAXSIZE usage on Redis >= 8.10.0 via client.info().","Keep max_count >= count when both are set.","Validate both numeric caps with the same helper used for count."],"tags":["redis-streams","validation","xread","version-gated","dataerror"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}