redis-parser is a high-performance JavaScript implementation of the Redis Serialization Protocol (RESP) parser, specifically designed for Node.js environments. It serves as the underlying parsing engine for popular Redis clients like node-redis and ioredis. The current stable version is 3.0.0. This library focuses on efficiently converting raw Redis protocol buffers into usable JavaScript data structures, supporting various RESP data types including strings, numbers, arrays, and errors. Its development prioritizes performance, especially for large data structures, and graceful handling of malformed input, making it a critical component for robust Redis client libraries. It also exports dedicated error classes for specific parsing and reply errors.
npm install redis-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes `redis-parser` with necessary callback functions for handling parsed replies, standard errors, and critical protocol errors. It demonstrates feeding various Redis protocol buffers to the parser's `execute` method and dynamically adjusting parsing options like `stringNumbers` for safe handling of large integers.
Upgrade Node.js to version 4 or higher. Alternatively, if upgrading Node.js is not possible, specify `"redis-parser": "~2.x"` in your `package.json`.
No direct fix is required as the library will now default to its JavaScript implementation. Users should test their applications for any unexpected performance regressions if `hiredis` was previously integral to their setup.
When initializing the Parser, set `stringNumbers: true` (e.g., `new Parser({ stringNumbers: true, ... })`) or call `parser.setStringNumbers(true)` on an existing instance.Initialize the Parser with `returnBuffers: true` (e.g., `new Parser({ returnBuffers: true, ... })`) or invoke `parser.setReturnBuffers(true)` on a parser instance.Provide a specific `returnFatalError` callback function during Parser instantiation to implement robust recovery logic for critical protocol violations.
Upgrade `redis-parser` to version 2.6.0 or newer to ensure the use of modern and optimized buffer allocation methods, reducing potential warnings or issues in newer Node.js environments.
Implement the `returnFatalError` callback to specifically handle protocol desynchronization. Within this callback, you should reset the parser state (`parser.reset()`), destroy the current network connection, and initiate a new one. All outstanding commands should be either rejected or re-queued for execution on the new connection.
Upgrade `redis-parser` to version 2.3.0 or higher. This version introduced significant performance improvements for handling large arrays, making the parsing time linear and much more resilient to arbitrary array sizes.
Ensure that any data fed to `parser.execute()` is first converted into a `Buffer`. For example, if you receive string data, use `parser.execute(Buffer.from(yourStringData))`.
No dependency data recorded yet.