Skip to content

Commit 4418ac6

Browse files
committed
Merge pull request #3 from NodeRedis/v.2.0
v.2.0
2 parents 83e3832 + f4fd340 commit 4418ac6

18 files changed

+1726
-786
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ logs
22
*.log
33
coverage
44
node_modules
5+
.idea

.jshintignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

.jshintrc

Lines changed: 0 additions & 20 deletions
This file was deleted.

.npmignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# IntelliJ project files
2+
.idea
3+
*.iml
4+
out
5+
gen
6+
7+
# Unrelevant files and folders
8+
benchmark
9+
coverage
10+
test
11+
.travis.yml
12+
.gitignore

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ node_js:
1212
- "0.10"
1313
- "0.12"
1414
- "4"
15-
- "5"
15+
- "6"
1616
install:
1717
- npm install
1818
- npm install hiredis

README.md

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
[![Build Status](https://travis-ci.org/NodeRedis/node-redis-parser.png?branch=master)](https://travis-ci.org/NodeRedis/node-redis-parser)
22
[![Code Climate](https://codeclimate.com/github/NodeRedis/node-redis-parser/badges/gpa.svg)](https://codeclimate.com/github/NodeRedis/node-redis-parser)
33
[![Test Coverage](https://codeclimate.com/github/NodeRedis/node-redis-parser/badges/coverage.svg)](https://codeclimate.com/github/NodeRedis/node-redis-parser/coverage)
4+
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
45

56
# redis-parser
67

7-
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.
109

1110
## Install
1211

@@ -21,7 +20,7 @@ npm install redis-parser
2120
```js
2221
var Parser = require('redis-parser');
2322

24-
new Parser(options);
23+
var myParser = new Parser(options);
2524
```
2625

2726
### Possible options
@@ -30,8 +29,6 @@ new Parser(options);
3029
* `returnError`: *function*; mandatory
3130
* `returnFatalError`: *function*; optional, defaults to the returnError function
3231
* `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!
3532

3633
### Example
3734

@@ -55,8 +52,7 @@ var parser = new Parser({
5552
},
5653
returnFatalError: function (err) {
5754
lib.returnFatalError(err);
58-
},
59-
name: 'auto' // This returns either the hiredis or the js parser instance depending on what's available
55+
}
6056
});
6157

6258
Library.prototype.streamHandler = function () {
@@ -70,7 +66,7 @@ You do not have to use the returnFatalError function. Fatal errors will be retur
7066

7167
And if you want to return buffers instead of strings, you can do this by adding the `returnBuffers` option.
7268

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.
7470

7571
```js
7672
// Same functions as in the first example
@@ -82,44 +78,24 @@ var parser = new Parser({
8278
returnError: function(err) {
8379
lib.returnError(err);
8480
},
85-
name: 'javascript', // Use the Javascript parser
86-
stringNumbers: true, // Return all numbers as string instead of a js number
8781
returnBuffers: true // All strings are returned as buffer e.g. <Buffer 48 65 6c 6c 6f>
8882
});
8983

9084
// The streamHandler as above
9185
```
9286

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-
10187
## Protocol errors
10288

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.
10590

10691
## Contribute
10792

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.
11194

11295
```
11396
npm install
11497
npm test
115-
116-
# Run node_redis benchmark (let's guess you cloned node_redis in another folder)
117-
cd ../redis
118-
npm install
119-
npm run benchmark parser=javascript > old.log
120-
# Replace the changed parser in the node_modules
121-
npm run benchmark parser=javascript > new.log
122-
node benchmarks/diff_multi_bench_output.js old.log new.log > improvement.log
98+
npm run benchmark
12399
```
124100

125101
## License

0 commit comments

Comments
 (0)