redis-parser
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -7,2 +7,3 @@ 'use strict'; | ||
this.name = 'hiredis'; | ||
this.returnBuffers = returnBuffers; | ||
this.reader = new hiredis.Reader({ | ||
@@ -18,2 +19,6 @@ return_buffers: returnBuffers | ||
// Protocol errors land here | ||
// Reset the parser. Otherwise new commands can't be processed properly | ||
this.reader = new hiredis.Reader({ | ||
return_buffers: this.returnBuffers | ||
}); | ||
this.returnFatalError(err); | ||
@@ -20,0 +25,0 @@ return void 0; |
{ | ||
"name": "redis-parser", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Javascript Redis protocol (RESP) parser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -93,2 +93,7 @@ [![Build Status](https://travis-ci.org/NodeRedis/node-redis-parser.png?branch=master)](https://travis-ci.org/NodeRedis/node-redis-parser) | ||
## Protocol errors | ||
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. | ||
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. | ||
## Contribute | ||
@@ -95,0 +100,0 @@ |
@@ -96,7 +96,9 @@ 'use strict'; | ||
it('parser error v2', function () { | ||
it('parser error resets the buffer', function () { | ||
var replyCount = 0; | ||
var errCount = 0; | ||
function checkReply (reply) { | ||
assert.strictEqual(reply[0], 'OK'); | ||
assert.strictEqual(reply.length, 1); | ||
assert(Buffer.isBuffer(reply[0])); | ||
assert.strictEqual(reply[0].toString(), 'CCC'); | ||
replyCount++; | ||
@@ -112,8 +114,12 @@ } | ||
returnFatalError: checkError, | ||
name: parserName | ||
name: parserName, | ||
returnBuffers: true | ||
}); | ||
parser.execute(new Buffer('*1\r\n+OK\r\nb$1`zasd\r\na')); | ||
// The chunk contains valid data after the protocol error | ||
parser.execute(new Buffer('*1\r\n+CCC\r\nb$1\r\nz\r\n+abc\r\n')); | ||
assert.strictEqual(replyCount, 1); | ||
assert.strictEqual(errCount, 1); | ||
parser.execute(new Buffer('*1\r\n+CCC\r\n')); | ||
assert.strictEqual(replyCount, 2); | ||
}); | ||
@@ -120,0 +126,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
33363
13
589
120
0