Gathering detailed insights and metrics for @saulx/redis-parser
Gathering detailed insights and metrics for @saulx/redis-parser
Gathering detailed insights and metrics for @saulx/redis-parser
Gathering detailed insights and metrics for @saulx/redis-parser
A high performance Redis protocol (RESP) parser for JavaScript. Used by Node Redis & ioredis.
npm install @saulx/redis-parser
Typescript
Module System
Min. Node Version
Node Version
NPM Version
72.7
Supply Chain
99.4
Quality
75.2
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
2,783
Last Day
2
Last Week
15
Last Month
29
Last Year
598
MIT License
88 Stars
163 Commits
36 Forks
6 Watchers
24 Branches
8 Contributors
Updated on Oct 28, 2024
Minified
Minified + Gzipped
Latest Version
1.0.0
Package Id
@saulx/redis-parser@1.0.0
Unpacked Size
25.24 kB
Size
7.23 kB
File Count
8
NPM Version
6.14.12
Node Version
14.16.1
Published on
Oct 22, 2021
Cumulative downloads
Total Downloads
Last Day
0%
2
Compared to previous day
Last Week
87.5%
15
Compared to previous week
Last Month
141.7%
29
Compared to previous month
Last Year
20.3%
598
Compared to previous year
A high performance javascript redis parser built for node_redis and ioredis. Parses all RESP data.
Install with NPM:
npm install redis-parser
1const Parser = require('redis-parser'); 2 3const myParser = new Parser(options);
returnReply
: function; mandatoryreturnError
: function; mandatoryreturnFatalError
: function; optional, defaults to the returnError functionreturnBuffers
: boolean; optional, defaults to falsestringNumbers
: boolean; optional, defaults to falsereset()
: reset the parser to it's initial statesetReturnBuffers(boolean)
: set the returnBuffers option on/off without resetting the parsersetStringNumbers(boolean)
: set the stringNumbers option on/off without resetting the parserRedisError
sub class of ErrorReplyError
sub class of RedisErrorParserError
sub class of RedisErrorAll Redis errors will be returned as ReplyErrors
while a parser error is returned as ParserError
.
All error classes can be imported by the npm redis-errors
package.
1const Parser = require("redis-parser"); 2 3class Library { 4 returnReply(reply) { /* ... */ } 5 returnError(err) { /* ... */ } 6 returnFatalError(err) { /* ... */ } 7 8 streamHandler() { 9 this.stream.on('data', (buffer) => { 10 // Here the data (e.g. `Buffer.from('$5\r\nHello\r\n'`)) 11 // is passed to the parser and the result is passed to 12 // either function depending on the provided data. 13 parser.execute(buffer); 14 }); 15 } 16} 17 18const lib = new Library(); 19 20const parser = new Parser({ 21 returnReply(reply) { 22 lib.returnReply(reply); 23 }, 24 returnError(err) { 25 lib.returnError(err); 26 }, 27 returnFatalError(err) { 28 lib.returnFatalError(err); 29 } 30});
You do not have to use the returnFatalError function. Fatal errors will be returned in the normal error function in that case.
And if you want to return buffers instead of strings, you can do this by adding the returnBuffers
option.
If you handle with big numbers that are to large for JS (Number.MAX_SAFE_INTEGER === 2^53 - 16) please use the stringNumbers
option. That way all numbers are going to be returned as String and you can handle them safely.
1// Same functions as in the first example
2
3const parser = new Parser({
4 returnReply(reply) {
5 lib.returnReply(reply);
6 },
7 returnError(err) {
8 lib.returnError(err);
9 },
10 returnBuffers: true, // All strings are returned as Buffer e.g. <Buffer 48 65 6c 6c 6f>
11 stringNumbers: true // All numbers are returned as String
12});
13
14// The streamHandler as above
To handle protocol errors (this is very unlikely to happen) gracefully you should add the returnFatalError option, reject any still running command (they might have been processed properly but the reply is just wrong), destroy the socket and reconnect. Note that while doing this no new command may be added, so all new commands have to be buffered in the meantime, otherwise a chunk might still contain partial data of a following command that was already processed properly but answered in the same chunk as the command that resulted in the protocol error.
The parser is highly optimized but there may still be further optimizations possible.
npm install
npm test
npm run benchmark
Currently the benchmark compares the performance against the hiredis parser:
HIREDIS: $ multiple chunks in a bulk string x 1,169,386 ops/sec ±1.24% (92 runs sampled)
JS PARSER: $ multiple chunks in a bulk string x 1,354,290 ops/sec ±1.69% (88 runs sampled)
HIREDIS BUF: $ multiple chunks in a bulk string x 633,639 ops/sec ±2.64% (84 runs sampled)
JS PARSER BUF: $ multiple chunks in a bulk string x 1,783,922 ops/sec ±0.47% (94 runs sampled)
HIREDIS: + multiple chunks in a string x 2,394,900 ops/sec ±0.31% (93 runs sampled)
JS PARSER: + multiple chunks in a string x 2,264,354 ops/sec ±0.29% (94 runs sampled)
HIREDIS BUF: + multiple chunks in a string x 953,733 ops/sec ±2.03% (82 runs sampled)
JS PARSER BUF: + multiple chunks in a string x 2,298,458 ops/sec ±0.79% (96 runs sampled)
HIREDIS: $ 4mb bulk string x 152 ops/sec ±2.03% (72 runs sampled)
JS PARSER: $ 4mb bulk string x 971 ops/sec ±0.79% (86 runs sampled)
HIREDIS BUF: $ 4mb bulk string x 169 ops/sec ±2.25% (71 runs sampled)
JS PARSER BUF: $ 4mb bulk string x 797 ops/sec ±7.08% (77 runs sampled)
HIREDIS: + simple string x 3,341,956 ops/sec ±1.01% (94 runs sampled)
JS PARSER: + simple string x 5,979,545 ops/sec ±0.38% (96 runs sampled)
HIREDIS BUF: + simple string x 1,031,745 ops/sec ±2.17% (76 runs sampled)
JS PARSER BUF: + simple string x 6,960,184 ops/sec ±0.28% (93 runs sampled)
HIREDIS: : integer x 3,897,626 ops/sec ±0.42% (91 runs sampled)
JS PARSER: : integer x 37,035,812 ops/sec ±0.32% (94 runs sampled)
JS PARSER STR: : integer x 25,515,070 ops/sec ±1.79% (83 runs sampled)
HIREDIS: : big integer x 3,036,704 ops/sec ±0.47% (92 runs sampled)
JS PARSER: : big integer x 10,616,464 ops/sec ±0.94% (94 runs sampled)
JS PARSER STR: : big integer x 7,098,146 ops/sec ±0.47% (94 runs sampled)
HIREDIS: * array x 51,542 ops/sec ±0.35% (94 runs sampled)
JS PARSER: * array x 87,090 ops/sec ±2.17% (94 runs sampled)
HIREDIS BUF: * array x 11,733 ops/sec ±1.80% (80 runs sampled)
JS PARSER BUF: * array x 149,430 ops/sec ±1.50% (88 runs sampled)
HIREDIS: * big nested array x 247 ops/sec ±0.93% (73 runs sampled)
JS PARSER: * big nested array x 286 ops/sec ±0.79% (83 runs sampled)
HIREDIS BUF: * big nested array x 217 ops/sec ±1.80% (73 runs sampled)
JS PARSER BUF: * big nested array x 175 ops/sec ±2.49% (37 runs sampled)
HIREDIS: - error x 108,110 ops/sec ±0.63% (84 runs sampled)
JS PARSER: - error x 172,665 ops/sec ±0.57% (85 runs sampled)
Platform info:
OSX 10.12.6
Node.js 10.0.0
Intel(R) Core(TM) i7-5600U CPU
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 1/17 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More