Skip to content

Commit 4944637

Browse files
committed
doc: update readme and changelog
1 parent b971e19 commit 4944637

File tree

3 files changed

+128
-124
lines changed

3 files changed

+128
-124
lines changed

README.md

Lines changed: 78 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Install with [NPM](https://npmjs.org/):
1515
## Usage
1616

1717
```js
18-
var Parser = require('redis-parser');
18+
const Parser = require('redis-parser');
1919

20-
var myParser = new Parser(options);
20+
const myParser = new Parser(options);
2121
```
2222

2323
### Options
@@ -31,8 +31,8 @@ var myParser = new Parser(options);
3131
### Functions
3232

3333
* `reset()`: reset the parser to it's initial state
34-
* `setReturnBuffers(boolean)`: (JSParser only) set the returnBuffers option on/off without resetting the parser
35-
* `setStringNumbers(boolean)`: (JSParser only) set the stringNumbers option on/off without resetting the parser
34+
* `setReturnBuffers(boolean)`: set the returnBuffers option on/off without resetting the parser
35+
* `setStringNumbers(boolean)`: set the stringNumbers option on/off without resetting the parser
3636

3737
### Error classes
3838

@@ -41,40 +41,43 @@ var myParser = new Parser(options);
4141
* `ParserError` sub class of RedisError
4242

4343
All Redis errors will be returned as `ReplyErrors` while a parser error is returned as `ParserError`.
44-
All error classes are exported by the parser.
44+
All error classes can be imported by the npm `redis-errors` package.
4545

4646
### Example
4747

4848
```js
49-
var Parser = require("redis-parser");
50-
51-
function Library () {}
52-
53-
Library.prototype.returnReply = function (reply) { ... }
54-
Library.prototype.returnError = function (err) { ... }
55-
Library.prototype.returnFatalError = function (err) { ... }
56-
57-
var lib = new Library();
58-
59-
var parser = new Parser({
60-
returnReply: function(reply) {
61-
lib.returnReply(reply);
62-
},
63-
returnError: function(err) {
64-
lib.returnError(err);
65-
},
66-
returnFatalError: function (err) {
67-
lib.returnFatalError(err);
68-
}
69-
});
70-
71-
Library.prototype.streamHandler = function () {
72-
this.stream.on('data', function (buffer) {
73-
// Here the data (e.g. `new Buffer('$5\r\nHello\r\n'`)) is passed to the parser and the result is passed to either function depending on the provided data.
74-
parser.execute(buffer);
49+
const Parser = require("redis-parser");
50+
51+
class Library {
52+
returnReply(reply) { /* ... */ }
53+
returnError(err) { /* ... */ }
54+
returnFatalError(err) { /* ... */ }
55+
56+
streamHandler() {
57+
this.stream.on('data', (buffer) => {
58+
// Here the data (e.g. `Buffer.from('$5\r\nHello\r\n'`))
59+
// is passed to the parser and the result is passed to
60+
// either function depending on the provided data.
61+
parser.execute(buffer);
7562
});
76-
};
63+
}
64+
}
65+
66+
const lib = new Library();
67+
68+
const parser = new Parser({
69+
returnReply(reply) {
70+
lib.returnReply(reply);
71+
},
72+
returnError(err) {
73+
lib.returnError(err);
74+
},
75+
returnFatalError(err) {
76+
lib.returnFatalError(err);
77+
}
78+
});
7779
```
80+
7881
You do not have to use the returnFatalError function. Fatal errors will be returned in the normal error function in that case.
7982

8083
And if you want to return buffers instead of strings, you can do this by adding the `returnBuffers` option.
@@ -84,15 +87,15 @@ If you handle with big numbers that are to large for JS (Number.MAX_SAFE_INTEGER
8487
```js
8588
// Same functions as in the first example
8689

87-
var parser = new Parser({
88-
returnReply: function(reply) {
89-
lib.returnReply(reply);
90-
},
91-
returnError: function(err) {
92-
lib.returnError(err);
93-
},
94-
returnBuffers: true, // All strings are returned as Buffer e.g. <Buffer 48 65 6c 6c 6f>
95-
stringNumbers: true // All numbers are returned as String
90+
const parser = new Parser({
91+
returnReply(reply) {
92+
lib.returnReply(reply);
93+
},
94+
returnError(err) {
95+
lib.returnError(err);
96+
},
97+
returnBuffers: true, // All strings are returned as Buffer e.g. <Buffer 48 65 6c 6c 6f>
98+
stringNumbers: true // All numbers are returned as String
9699
});
97100

98101
// The streamHandler as above
@@ -112,50 +115,50 @@ The parser is highly optimized but there may still be further optimizations poss
112115

113116
Currently the benchmark compares the performance against the hiredis parser:
114117

115-
HIREDIS: $ multiple chunks in a bulk string x 859,880 ops/sec ±1.22% (82 runs sampled)
116-
HIREDIS BUF: $ multiple chunks in a bulk string x 608,869 ops/sec ±1.72% (85 runs sampled)
117-
JS PARSER: $ multiple chunks in a bulk string x 910,590 ops/sec ±0.87% (89 runs sampled)
118-
JS PARSER BUF: $ multiple chunks in a bulk string x 1,299,507 ops/sec ±2.18% (84 runs sampled)
118+
HIREDIS: $ multiple chunks in a bulk string x 994,387 ops/sec ±0.22% (554 runs sampled)
119+
JS PARSER: $ multiple chunks in a bulk string x 1,010,728 ops/sec ±0.28% (559 runs sampled)
120+
HIREDIS BUF: $ multiple chunks in a bulk string x 648,742 ops/sec ±0.80% (526 runs sampled)
121+
JS PARSER BUF: $ multiple chunks in a bulk string x 1,728,849 ops/sec ±0.41% (555 runs sampled)
119122

120-
HIREDIS: + multiple chunks in a string x 1,787,203 ops/sec ±0.58% (96 runs sampled)
121-
HIREDIS BUF: + multiple chunks in a string x 943,584 ops/sec ±1.62% (87 runs sampled)
122-
JS PARSER: + multiple chunks in a string x 2,008,264 ops/sec ±1.01% (91 runs sampled)
123-
JS PARSER BUF: + multiple chunks in a string x 2,045,546 ops/sec ±0.78% (91 runs sampled)
123+
HIREDIS: + multiple chunks in a string x 1,861,132 ops/sec ±0.18% (564 runs sampled)
124+
JS PARSER: + multiple chunks in a string x 2,131,892 ops/sec ±0.31% (558 runs sampled)
125+
HIREDIS BUF: + multiple chunks in a string x 965,132 ops/sec ±0.58% (521 runs sampled)
126+
JS PARSER BUF: + multiple chunks in a string x 2,304,482 ops/sec ±0.31% (559 runs sampled)
124127

125-
HIREDIS: $ 4mb bulk string x 310 ops/sec ±1.58% (75 runs sampled)
126-
HIREDIS BUF: $ 4mb bulk string x 471 ops/sec ±2.28% (78 runs sampled)
127-
JS PARSER: $ 4mb bulk string x 747 ops/sec ±2.43% (85 runs sampled)
128-
JS PARSER BUF: $ 4mb bulk string x 846 ops/sec ±5.52% (72 runs sampled)
128+
HIREDIS: $ 4mb bulk string x 269 ops/sec ±0.56% (452 runs sampled)
129+
JS PARSER: $ 4mb bulk string x 763 ops/sec ±0.25% (466 runs sampled)
130+
HIREDIS BUF: $ 4mb bulk string x 336 ops/sec ±0.59% (459 runs sampled)
131+
JS PARSER BUF: $ 4mb bulk string x 994 ops/sec ±0.36% (482 runs sampled)
129132

130-
HIREDIS: + simple string x 2,324,866 ops/sec ±1.61% (90 runs sampled)
131-
HIREDIS BUF: + simple string x 1,085,823 ops/sec ±2.47% (82 runs sampled)
132-
JS PARSER: + simple string x 4,567,358 ops/sec ±1.97% (81 runs sampled)
133-
JS PARSER BUF: + simple string x 5,433,901 ops/sec ±0.66% (93 runs sampled)
133+
HIREDIS: + simple string x 2,504,305 ops/sec ±0.19% (563 runs sampled)
134+
JS PARSER: + simple string x 5,121,952 ops/sec ±0.30% (560 runs sampled)
135+
HIREDIS BUF: + simple string x 1,122,899 ops/sec ±0.52% (516 runs sampled)
136+
JS PARSER BUF: + simple string x 5,907,323 ops/sec ±0.23% (562 runs sampled)
134137

135-
HIREDIS: : integer x 2,332,946 ops/sec ±0.47% (93 runs sampled)
136-
JS PARSER: : integer x 17,730,449 ops/sec ±0.73% (91 runs sampled)
137-
JS PARSER STR: : integer x 12,942,037 ops/sec ±0.51% (92 runs sampled)
138+
HIREDIS: : integer x 2,461,376 ops/sec ±0.14% (561 runs sampled)
139+
JS PARSER: : integer x 18,543,688 ops/sec ±0.19% (539 runs sampled)
140+
JS PARSER STR: : integer x 14,149,305 ops/sec ±0.24% (561 runs sampled)
138141

139-
HIREDIS: : big integer x 2,012,572 ops/sec ±0.33% (93 runs sampled)
140-
JS PARSER: : big integer x 10,210,923 ops/sec ±0.94% (94 runs sampled)
141-
JS PARSER STR: : big integer x 4,453,320 ops/sec ±0.52% (94 runs sampled)
142+
HIREDIS: : big integer x 2,114,270 ops/sec ±0.15% (561 runs sampled)
143+
JS PARSER: : big integer x 10,794,439 ops/sec ±0.25% (560 runs sampled)
144+
JS PARSER STR: : big integer x 4,594,807 ops/sec ±0.24% (558 runs sampled)
142145

143-
HIREDIS: * array x 44,479 ops/sec ±0.55% (94 runs sampled)
144-
HIREDIS BUF: * array x 14,391 ops/sec ±1.04% (86 runs sampled)
145-
JS PARSER: * array x 53,796 ops/sec ±2.08% (79 runs sampled)
146-
JS PARSER BUF: * array x 72,428 ops/sec ±0.72% (93 runs sampled)
146+
HIREDIS: * array x 45,597 ops/sec ±0.23% (565 runs sampled)
147+
JS PARSER: * array x 68,396 ops/sec ±0.30% (563 runs sampled)
148+
HIREDIS BUF: * array x 14,726 ops/sec ±0.39% (498 runs sampled)
149+
JS PARSER BUF: * array x 80,961 ops/sec ±0.25% (561 runs sampled)
147150

148-
HIREDIS: * big nested array x 217 ops/sec ±0.97% (83 runs sampled)
149-
HIREDIS BUF: * big nested array x 255 ops/sec ±2.28% (77 runs sampled)
150-
JS PARSER: * big nested array x 242 ops/sec ±1.10% (85 runs sampled)
151-
JS PARSER BUF: * big nested array x 375 ops/sec ±1.21% (88 runs sampled)
151+
HIREDIS: * big nested array x 212 ops/sec ±0.17% (511 runs sampled)
152+
JS PARSER: * big nested array x 243 ops/sec ±0.21% (496 runs sampled)
153+
HIREDIS BUF: * big nested array x 207 ops/sec ±0.37% (430 runs sampled)
154+
JS PARSER BUF: * big nested array x 297 ops/sec ±1.10% (421 runs sampled)
152155

153-
HIREDIS: - error x 78,821 ops/sec ±0.80% (93 runs sampled)
154-
JS PARSER: - error x 143,382 ops/sec ±0.75% (92 runs sampled)
156+
HIREDIS: - error x 168,761 ops/sec ±0.28% (559 runs sampled)
157+
JS PARSER: - error x 424,257 ops/sec ±0.28% (557 runs sampled)
155158

156159
Platform info:
157-
Ubuntu 16.10
158-
Node.js 7.4.0
160+
Ubuntu 17.04
161+
Node.js 7.10.0
159162
Intel(R) Core(TM) i7-5600U CPU
160163

161164
## License

benchmark/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const parserStr = new Parser(options)
7575

7676
// BULK STRINGS
7777

78-
suite.add('HIREDIS: $ multiple chunks in a bulk string', function () {
78+
suite.add('HIREDIS: $ multiple chunks in a bulk string', function () {
7979
parserHiRedis.execute(startBuffer)
8080
parserHiRedis.execute(chunkBuffer)
8181
parserHiRedis.execute(chunkBuffer)
@@ -91,7 +91,7 @@ suite.add('JS PARSER: $ multiple chunks in a bulk string', function () {
9191
parser.execute(endBuffer)
9292
})
9393

94-
suite.add('HIREDIS BUF: $ multiple chunks in a bulk string', function () {
94+
suite.add('HIREDIS BUF: $ multiple chunks in a bulk string', function () {
9595
parserHiRedisBuffer.execute(startBuffer)
9696
parserHiRedisBuffer.execute(chunkBuffer)
9797
parserHiRedisBuffer.execute(chunkBuffer)
@@ -109,7 +109,7 @@ suite.add('JS PARSER BUF: $ multiple chunks in a bulk string', function () {
109109

110110
// CHUNKED STRINGS
111111

112-
suite.add('\nHIREDIS: + multiple chunks in a string', function () {
112+
suite.add('\nHIREDIS: + multiple chunks in a string', function () {
113113
parserHiRedis.execute(chunkedStringPart1)
114114
parserHiRedis.execute(chunkedStringPart2)
115115
})
@@ -119,7 +119,7 @@ suite.add('JS PARSER: + multiple chunks in a string', function () {
119119
parser.execute(chunkedStringPart2)
120120
})
121121

122-
suite.add('HIREDIS BUF: + multiple chunks in a string', function () {
122+
suite.add('HIREDIS BUF: + multiple chunks in a string', function () {
123123
parserHiRedisBuffer.execute(chunkedStringPart1)
124124
parserHiRedisBuffer.execute(chunkedStringPart2)
125125
})
@@ -131,7 +131,7 @@ suite.add('JS PARSER BUF: + multiple chunks in a string', function () {
131131

132132
// BIG BULK STRING
133133

134-
suite.add('\nHIREDIS: $ 4mb bulk string', function () {
134+
suite.add('\nHIREDIS: $ 4mb bulk string', function () {
135135
parserHiRedis.execute(startBigBuffer)
136136
for (var i = 0; i < 64; i++) {
137137
parserHiRedis.execute(chunks[i])
@@ -147,7 +147,7 @@ suite.add('JS PARSER: $ 4mb bulk string', function () {
147147
parser.execute(endBuffer)
148148
})
149149

150-
suite.add('HIREDIS BUF: $ 4mb bulk string', function () {
150+
suite.add('HIREDIS BUF: $ 4mb bulk string', function () {
151151
parserHiRedisBuffer.execute(startBigBuffer)
152152
for (var i = 0; i < 64; i++) {
153153
parserHiRedisBuffer.execute(chunks[i])
@@ -165,7 +165,7 @@ suite.add('JS PARSER BUF: $ 4mb bulk string', function () {
165165

166166
// STRINGS
167167

168-
suite.add('\nHIREDIS: + simple string', function () {
168+
suite.add('\nHIREDIS: + simple string', function () {
169169
parserHiRedis.execute(stringBuffer)
170170
})
171171

@@ -183,7 +183,7 @@ suite.add('JS PARSER BUF: + simple string', function () {
183183

184184
// INTEGERS
185185

186-
suite.add('\nHIREDIS: : integer', function () {
186+
suite.add('\nHIREDIS: : integer', function () {
187187
parserHiRedis.execute(integerBuffer)
188188
})
189189

@@ -197,7 +197,7 @@ suite.add('JS PARSER STR: : integer', function () {
197197

198198
// BIG INTEGER
199199

200-
suite.add('\nHIREDIS: : big integer', function () {
200+
suite.add('\nHIREDIS: : big integer', function () {
201201
parserHiRedis.execute(bigIntegerBuffer)
202202
})
203203

@@ -211,15 +211,15 @@ suite.add('JS PARSER STR: : big integer', function () {
211211

212212
// ARRAYS
213213

214-
suite.add('\nHIREDIS: * array', function () {
214+
suite.add('\nHIREDIS: * array', function () {
215215
parserHiRedis.execute(arrayBuffer)
216216
})
217217

218218
suite.add('JS PARSER: * array', function () {
219219
parser.execute(arrayBuffer)
220220
})
221221

222-
suite.add('HIREDIS BUF: * array', function () {
222+
suite.add('HIREDIS BUF: * array', function () {
223223
parserHiRedisBuffer.execute(arrayBuffer)
224224
})
225225

@@ -229,7 +229,7 @@ suite.add('JS PARSER BUF: * array', function () {
229229

230230
// BIG NESTED ARRAYS
231231

232-
suite.add('\nHIREDIS: * big nested array', function () {
232+
suite.add('\nHIREDIS: * big nested array', function () {
233233
for (var i = 0; i < bigArrayChunks.length; i++) {
234234
parserHiRedis.execute(bigArrayChunks[i])
235235
}
@@ -241,7 +241,7 @@ suite.add('JS PARSER: * big nested array', function () {
241241
}
242242
})
243243

244-
suite.add('HIREDIS BUF: * big nested array', function () {
244+
suite.add('HIREDIS BUF: * big nested array', function () {
245245
for (var i = 0; i < bigArrayChunks.length; i++) {
246246
parserHiRedisBuffer.execute(bigArrayChunks[i])
247247
}
@@ -255,7 +255,7 @@ suite.add('JS PARSER BUF: * big nested array', function () {
255255

256256
// ERRORS
257257

258-
suite.add('\nHIREDIS: - error', function () {
258+
suite.add('\nHIREDIS: - error', function () {
259259
parserHiRedis.execute(errorBuffer)
260260
})
261261

0 commit comments

Comments
 (0)