You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A high performance redis parser solution built for [node_redis](https://github.com/NodeRedis/node_redis) and [ioredis](https://github.com/ioredis/luin).
8
-
9
-
Generally all [RESP](http://redis.io/topics/protocol) data will be properly parsed by the parser.
8
+
A high performance javascript redis parser built for [node_redis](https://github.com/NodeRedis/node_redis) and [ioredis](https://github.com/luin/ioredis). Parses all [RESP](http://redis.io/topics/protocol) data.
10
9
11
10
## Install
12
11
@@ -21,7 +20,7 @@ npm install redis-parser
21
20
```js
22
21
var Parser =require('redis-parser');
23
22
24
-
newParser(options);
23
+
var myParser =newParser(options);
25
24
```
26
25
27
26
### Possible options
@@ -30,8 +29,6 @@ new Parser(options);
30
29
*`returnError`: *function*; mandatory
31
30
*`returnFatalError`: *function*; optional, defaults to the returnError function
32
31
*`returnBuffers`: *boolean*; optional, defaults to false
33
-
*`name`: *'javascript'|'hiredis'|'auto'|null*; optional, defaults to hiredis and falls back to the js parser if not available or if the stringNumbers option is choosen. Setting this to 'auto' or null is going to automatically determine what parser is available and chooses that one.
34
-
*`stringNumbers`: *boolean*; optional, defaults to false. This is only available for the javascript parser at the moment!
35
32
36
33
### Example
37
34
@@ -55,8 +52,7 @@ var parser = new Parser({
55
52
},
56
53
returnFatalError:function (err) {
57
54
lib.returnFatalError(err);
58
-
},
59
-
name:'auto'// This returns either the hiredis or the js parser instance depending on what's available
55
+
}
60
56
});
61
57
62
58
Library.prototype.streamHandler=function () {
@@ -70,7 +66,7 @@ You do not have to use the returnFatalError function. Fatal errors will be retur
70
66
71
67
And if you want to return buffers instead of strings, you can do this by adding the `returnBuffers` option.
72
68
73
-
If you handle big numbers, you should pass the `stringNumbers` option. That case numbers above 2^53 can be handled properly without reduced precision.
69
+
Big numbers that are too large for JS are automatically stringified.
74
70
75
71
```js
76
72
// Same functions as in the first example
@@ -82,44 +78,24 @@ var parser = new Parser({
82
78
returnError:function(err) {
83
79
lib.returnError(err);
84
80
},
85
-
name:'javascript', // Use the Javascript parser
86
-
stringNumbers:true, // Return all numbers as string instead of a js number
87
81
returnBuffers:true// All strings are returned as buffer e.g. <Buffer 48 65 6c 6c 6f>
88
82
});
89
83
90
84
// The streamHandler as above
91
85
```
92
86
93
-
## Further info
94
-
95
-
The [hiredis](https://github.com/redis/hiredis) parser is still the fasted parser for
96
-
Node.js and therefor used as default in redis-parser if the hiredis parser is available.
97
-
98
-
Otherwise the pure js NodeRedis parser is choosen that is almost as fast as the
99
-
hiredis parser besides some situations in which it'll be a bit slower.
100
-
101
87
## Protocol errors
102
88
103
-
To handle protocol errors (this is very unlikely to happen) gracefuly 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.
104
-
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.
89
+
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.
105
90
106
91
## Contribute
107
92
108
-
The js parser is already optimized but there are likely further optimizations possible.
109
-
Besides running the tests you'll also have to run the change at least against the node_redis benchmark suite and post the improvement in the PR.
110
-
If you want to write a own parser benchmark, that would also be great!
93
+
The parser is highly optimized but there may still be further optimizations possible.
111
94
112
95
```
113
96
npm install
114
97
npm test
115
-
116
-
# Run node_redis benchmark (let's guess you cloned node_redis in another folder)
0 commit comments