{"library":"hiredis","code":"import hiredis\n\n# Create a Reader instance to parse Redis protocol data\nreader = hiredis.Reader()\n\n# Example 1: Parse a simple string reply ('+OK\\r\\n')\nreader.feed(b\"+OK\\r\\n\")\nresult_ok = reader.gets()\nprint(f\"Parsed simple string: {result_ok}\")\n\n# Example 2: Parse a bulk string reply ('$5\\r\\nhello\\r\\n')\nreader.feed(b\"$5\\r\\nhello\\r\\n\")\nresult_hello = reader.gets()\nprint(f\"Parsed bulk string: {result_hello}\")\n\n# Example 3: Parse an array reply ('*2\\r\\n$5\\r\\nhello\\r\\n$5\\r\\nworld\\r\\n')\nreader.feed(b\"*2\\r\\n$5\\r\\nhello\\r\\n$5\\r\\nworld\\r\\n\")\nresult_array = reader.gets()\nprint(f\"Parsed array: {result_array}\")\n\n# Example 4: Handle incomplete data - gets() returns False if no full reply is available\nreader.feed(b\"$6\\r\\nfoobar\")\nincomplete_result = reader.gets()\nprint(f\"Incomplete data (should be False): {incomplete_result}\")\nreader.feed(b\"\\r\\n\") # Complete the data\ncompleted_result = reader.gets()\nprint(f\"Completed data: {completed_result}\")","lang":"python","description":"This quickstart demonstrates the direct usage of `hiredis.Reader` to parse Redis protocol strings. The `feed()` method takes raw bytes, and `gets()` retrieves the next complete parsed reply. It handles different Redis data types and returns `False` if a complete reply is not yet available in the buffer.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}