├── .gitignore ├── .jshintrc ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── lib ├── commands.js └── disque.js ├── package.json └── test ├── .jshintrc ├── functional └── connection.js ├── helpers ├── global.js ├── mock_server.js └── parser.js └── mocha.opts /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | 29 | test.js 30 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "bitwise":false, 3 | "boss":true, 4 | "curly":false, 5 | "eqeqeq":true, 6 | "freeze":true, 7 | "immed":true, // deprecated 8 | "indent":2, // deprecated 9 | "latedef":"true", 10 | "newcap":true, // deprecated 11 | "noarg":true, 12 | "node":true, 13 | "strict":true, 14 | "undef":true, 15 | "esnext":false, 16 | "unused": "vars", 17 | "nonbsp": true, 18 | "maxdepth": 8, 19 | "quotmark": true, // deprecated 20 | 21 | /* relaxing options */ 22 | "laxbreak":true, 23 | "laxcomma":true, 24 | 25 | /* questionable */ 26 | "loopfunc":true, 27 | 28 | "globals": { 29 | "Promise": true 30 | }, 31 | 32 | "predef": [ 33 | "Map" 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - '0.11.16' 5 | - '0.12' 6 | - 'iojs' 7 | 8 | script: 9 | - npm run test:cov 10 | 11 | addons: 12 | code_climate: 13 | repo_token: dc8a92b1d9b3efdc3f2173943d07b4f54f7970448a7055f0d9cc051eff8a93e2 14 | 15 | after_success: 16 | - cat ./coverage/lcov.info | ./node_modules/.bin/codeclimate 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Zihua Li 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Disque 2 | 3 | [![Build Status](https://travis-ci.org/luin/disque.svg?branch=master)](https://travis-ci.org/luin/disque) 4 | [![Code Climate](https://codeclimate.com/github/luin/disque/badges/gpa.svg)](https://codeclimate.com/github/luin/disque) 5 | [![Dependency Status](https://david-dm.org/luin/disque.svg)](https://david-dm.org/luin/disque) 6 | [![Join the chat at https://gitter.im/luin/disque](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/luin/disque?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 7 | 8 | [Disque](https://github.com/antirez/disque) client for Node and io.js based on [ioredis](https://github.com/luin/ioredis). 9 | 10 | Support Node.js >= 0.11.16 or io.js. 11 | 12 | ## Install 13 | 14 | ```shell 15 | $ npm install disque 16 | ``` 17 | 18 | ## Usage 19 | 20 | ```javascript 21 | var Disque = require('disque'); 22 | var disque = new Disque([ 23 | { port: 7711, host: 'localhost' }, 24 | { port: 7712, host: 'localhost' }, 25 | ]); 26 | 27 | disque.addjob('greeting', 'hello world!', 0, function () { 28 | console.log(arguments); 29 | }); 30 | ``` 31 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require('./lib/disque'); 4 | -------------------------------------------------------------------------------- /lib/commands.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = [ 4 | 'addjob', 5 | 'getjob', 6 | 'qlen', 7 | 'qpeek', 8 | 'show', 9 | 'ackjob', 10 | 'fastack', 11 | 'info', 12 | 'hello', 13 | 'enqueue', 14 | 'dequeue', 15 | 'deljob' 16 | ]; 17 | -------------------------------------------------------------------------------- /lib/disque.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var Redis = require('ioredis'); 4 | var util = require('util'); 5 | var _ = require('lodash'); 6 | var commands = require('./commands'); 7 | var debug = require('debug')('disque:disque'); 8 | 9 | function Disque(startupNodes, options) { 10 | Redis.call(this, _.assign(options || {}, { 11 | clusterRetryStrategy: null, 12 | lazyConnect: true, 13 | disqueNodes: startupNodes 14 | })); 15 | 16 | this.nodes = {}; 17 | this.connect(); 18 | var _this = this; 19 | this.on('connect', function () { 20 | _this.client.on('connect', function () { 21 | _this.stream = _this.client.stream; 22 | _this.sendCommand = _this.client.sendCommand.bind(_this.client); 23 | _this.setStatus('ready'); 24 | if (_this.offlineQueue.length) { 25 | debug('send %d commands in offline queue', _this.offlineQueue.length); 26 | while (_this.offlineQueue.length > 0) { 27 | var item = _this.offlineQueue.shift(); 28 | _this.client.sendCommand(item.command, item.stream); 29 | } 30 | } 31 | }); 32 | }); 33 | } 34 | 35 | util.inherits(Disque, Redis); 36 | 37 | Disque.prototype.getBuiltinCommands().forEach(function (commandName) { 38 | delete Disque.prototype[commandName]; 39 | }); 40 | 41 | _.forEach(commands, function (commandName) { 42 | Disque.prototype[commandName] = Disque.prototype.createBuiltinCommand(commandName).string; 43 | Disque.prototype[commandName + 'Buffer'] = Disque.prototype.createBuiltinCommand(commandName).buffer; 44 | }); 45 | 46 | Disque.prototype.connect = function (callback) { 47 | if (this.status === 'connecting' || this.status === 'connect') { 48 | return false; 49 | } 50 | this.setStatus('connecting'); 51 | this.connecting = true; 52 | this.retryAttempts = 0; 53 | this.condition = { mode: {} }; 54 | 55 | if (typeof this.currentPoint !== 'number') { 56 | this.currentPoint = -1; 57 | } 58 | 59 | var _this = this; 60 | connectToNext(); 61 | 62 | function connectToNext() { 63 | _this.currentPoint += 1; 64 | if (_this.currentPoint === _this.options.disqueNodes.length) { 65 | _this.emit('error', new Error('All nodes are unreachable.')); 66 | return; 67 | } 68 | 69 | var endpoint = _this.options.disqueNodes[_this.currentPoint]; 70 | var client = new Redis({ 71 | port: endpoint.port, 72 | host: endpoint.host, 73 | retryStrategy: null, 74 | enableReadyCheck: false, 75 | connectTimeout: 2000 76 | }); 77 | client.cluster('nodes', function (err, lines) { 78 | client.disconnect(); 79 | if (!_this.connecting) { 80 | return; 81 | } 82 | if (err) { 83 | debug('failed to connect to node %s:%s because %s', endpoint.host, endpoint.port, err); 84 | return connectToNext(); 85 | } 86 | if (typeof lines !== 'string') { 87 | debug('connected to node %s:%s successfully, but got a invalid reply: %s', endpoint.host, endpoint.port, lines); 88 | connectToNext(); 89 | } 90 | debug('connected to node %s:%s', endpoint.host, endpoint.port); 91 | lines.split('\n').forEach(function (line) { 92 | var res = line.split(' '); 93 | var id = res[0]; 94 | var host = res[1]; 95 | var flag = res[2]; 96 | var prefix = id.slice(0, 8); 97 | if (flag === 'myself') { 98 | _this.client = new Redis({ 99 | port: client.options.port, 100 | host: client.options.host, 101 | enableReadyCheck: false 102 | }); 103 | _this.prefix = prefix; 104 | } 105 | _this.nodes[prefix] = host; 106 | }); 107 | _this.setStatus('connect'); 108 | }); 109 | } 110 | }; 111 | 112 | module.exports = Disque; 113 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "disque", 3 | "version": "0.0.1", 4 | "description": "A redis-based job queue that never sucks", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "NODE_ENV=test DEBUG=disque:* mocha", 8 | "test:cov": "NODE_ENV=test DEBUG=disque:* node ./node_modules/istanbul/lib/cli.js cover --preserve-comments ./node_modules/mocha/bin/_mocha -- -R spec" 9 | }, 10 | "author": { 11 | "name": "luin", 12 | "email": "i@zihua.li", 13 | "url": "http://zihua.li" 14 | }, 15 | "keywords": [ 16 | "disque", 17 | "cluster", 18 | "queue", 19 | "message" 20 | ], 21 | "repository": { 22 | "type": "git", 23 | "url": "git://github.com/luin/disque.git" 24 | }, 25 | "license": "MIT", 26 | "dependencies": { 27 | "debug": "^2.1.3", 28 | "ioredis": "^1.1.4", 29 | "lodash": "^3.8.0" 30 | }, 31 | "engines": { 32 | "node": ">= 0.11.16", 33 | "iojs": ">= 1.0.0" 34 | }, 35 | "devDependencies": { 36 | "chai": "^2.3.0", 37 | "codeclimate-test-reporter": "0.0.4", 38 | "istanbul": "^0.3.13", 39 | "mocha": "^2.2.4", 40 | "server-destroy": "^1.0.0", 41 | "sinon": "^1.14.1" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../.jshintrc", 3 | "predef": [ 4 | "Disque", 5 | "describe", 6 | "it", 7 | "before", 8 | "beforeEach", 9 | "after", 10 | "afterEach", 11 | "suite", 12 | "setup", 13 | "test", 14 | "Map", 15 | "expect", 16 | "stub", 17 | "MockServer" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/functional/connection.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | describe('connection', function () { 4 | it('should connect to disque server successfully', function (done) { 5 | var node = new MockServer(7712, function (argv) { 6 | if (argv.toString() === 'cluster,nodes') { 7 | return '7a656412ba0761bbcab0ebf2b4247e84694cfcea :7712 myself 0 0 connected\n'; 8 | } 9 | }); 10 | node.on('connect', function () { 11 | disque.disconnect(); 12 | disconnect([node], done); 13 | }); 14 | 15 | var disque = new Disque([{ port: 7712 }]); 16 | }); 17 | }); 18 | 19 | function disconnect (clients, callback) { 20 | var pending = 0; 21 | 22 | for (var i = 0; i < clients.length; ++i) { 23 | pending += 1; 24 | clients[i].disconnect(check); 25 | } 26 | 27 | function check () { 28 | if (!--pending) { 29 | callback(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/helpers/global.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | GLOBAL.expect = require('chai').expect; 4 | 5 | var sinon = require('sinon'); 6 | GLOBAL.stub = sinon.stub.bind(sinon); 7 | 8 | GLOBAL.Disque = require('../..'); 9 | GLOBAL.MockServer = require('./mock_server'); 10 | -------------------------------------------------------------------------------- /test/helpers/mock_server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var net = require('net'); 4 | var util = require('util'); 5 | var EventEmitter = require('events').EventEmitter; 6 | var enableDestroy = require('server-destroy'); 7 | var Parser = require('./parser'); 8 | 9 | function MockServer (port, handler) { 10 | EventEmitter.call(this); 11 | 12 | var _this = this; 13 | this.handler = handler; 14 | this.socket = net.createServer(function (c) { 15 | process.nextTick(function () { 16 | _this.emit('connect', c); 17 | }); 18 | 19 | var parser = new Parser({ returnBuffer: false }); 20 | parser.on('reply', function (args) { 21 | if (_this.handler) { 22 | _this.write(c, _this.handler(args)); 23 | } else { 24 | _this.write(c, MockServer.REDIS_OK); 25 | } 26 | }); 27 | 28 | c.on('end', function () { 29 | _this.emit('disconnect', c); 30 | }); 31 | 32 | c.on('data', function (data) { 33 | parser.execute(data); 34 | }); 35 | }); 36 | this.socket.listen(port); 37 | enableDestroy(this.socket); 38 | } 39 | 40 | util.inherits(MockServer, EventEmitter); 41 | 42 | MockServer.prototype.disconnect = function (callback) { 43 | this.socket.destroy(callback); 44 | }; 45 | 46 | MockServer.prototype.write = function (c, data) { 47 | if (c.writable) { 48 | c.write(convert('', data)); 49 | } 50 | 51 | function convert(str, data) { 52 | var result; 53 | if (typeof data === 'undefined') { 54 | data = MockServer.REDIS_OK; 55 | } 56 | if (data === MockServer.REDIS_OK) { 57 | result = '+OK\r\n'; 58 | } else if (data instanceof Error) { 59 | result = '-' + data.message + '\r\n'; 60 | } else if (Array.isArray(data)) { 61 | result = '*' + data.length + '\r\n'; 62 | data.forEach(function (item) { 63 | result += convert(str, item); 64 | }); 65 | } else if (typeof data === 'number') { 66 | result = ':' + data + '\r\n'; 67 | } else if (data === null) { 68 | result = '$-1\r\n'; 69 | } else { 70 | data = data.toString(); 71 | result = '$' + data.length + '\r\n'; 72 | result += data + '\r\n'; 73 | } 74 | return str + result; 75 | } 76 | }; 77 | 78 | MockServer.REDIS_OK = '+OK'; 79 | 80 | module.exports = MockServer; 81 | -------------------------------------------------------------------------------- /test/helpers/parser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var events = require('events'); 4 | var util = require('util'); 5 | 6 | var extendsError = function (name) { 7 | var errorClass = function (message) { 8 | Error.call(this); 9 | Error.captureStackTrace(this, this.constructor); 10 | 11 | this.name = name; 12 | this.message = message; 13 | }; 14 | 15 | // inherit from Error 16 | util.inherits(errorClass, Error); 17 | 18 | return errorClass; 19 | }; 20 | 21 | var ReplyError = extendsError('ReplyError'); 22 | var IncompleteReadBuffer = extendsError('IncompleteReadBuffer'); 23 | 24 | function Packet(type, size) { 25 | this.type = type; 26 | this.size = +size; 27 | } 28 | 29 | function ReplyParser(options) { 30 | this.options = options || { }; 31 | 32 | this._buffer = null; 33 | this._offset = 0; 34 | this._encoding = 'utf-8'; 35 | this._reply_type = null; 36 | } 37 | 38 | util.inherits(ReplyParser, events.EventEmitter); 39 | 40 | module.exports = ReplyParser; 41 | 42 | // Buffer.toString() is quite slow for small strings 43 | function smallToString(buf, start, end) { 44 | var tmp = '', i; 45 | 46 | for (i = start; i < end; i++) { 47 | tmp += String.fromCharCode(buf[i]); 48 | } 49 | 50 | return tmp; 51 | } 52 | 53 | ReplyParser.prototype._parseResult = function (type) { 54 | var start, end, offset, packetHeader; 55 | 56 | if (type === 43 || type === 45) { // + or - 57 | // up to the delimiter 58 | end = this._packetEndOffset() - 1; 59 | start = this._offset; 60 | 61 | // include the delimiter 62 | this._offset = end + 2; 63 | 64 | if (end > this._buffer.length) { 65 | this._offset = start; 66 | throw new IncompleteReadBuffer('Wait for more data.'); 67 | } 68 | 69 | if (type === 45) { 70 | return new ReplyError(this._buffer.toString(this._encoding, start, end)); 71 | } 72 | if (this.options.returnBuffers) { 73 | return this._buffer.slice(start, end); 74 | } else { 75 | if (end - start < 65536) { // completely arbitrary 76 | return smallToString(this._buffer, start, end); 77 | } else { 78 | return this._buffer.toString(this._encoding, start, end); 79 | } 80 | } 81 | } else if (type === 58) { // : 82 | // up to the delimiter 83 | end = this._packetEndOffset() - 1; 84 | start = this._offset; 85 | 86 | // include the delimiter 87 | this._offset = end + 2; 88 | 89 | if (end > this._buffer.length) { 90 | this._offset = start; 91 | throw new IncompleteReadBuffer('Wait for more data.'); 92 | } 93 | 94 | // TODO number? 95 | // if (this.options.returnBuffers) { 96 | // return this._buffer.slice(start, end); 97 | // } 98 | 99 | // return the coerced numeric value 100 | return +smallToString(this._buffer, start, end); 101 | } else if (type === 36) { // $ 102 | // set a rewind point, as the packet could be larger than the 103 | // buffer in memory 104 | offset = this._offset - 1; 105 | 106 | packetHeader = new Packet(type, this.parseHeader()); 107 | 108 | // packets with a size of -1 are considered null 109 | if (packetHeader.size === -1) { 110 | return undefined; 111 | } 112 | 113 | end = this._offset + packetHeader.size; 114 | start = this._offset; 115 | 116 | // set the offset to after the delimiter 117 | this._offset = end + 2; 118 | 119 | if (end > this._buffer.length) { 120 | this._offset = offset; 121 | throw new IncompleteReadBuffer('Wait for more data.'); 122 | } 123 | 124 | if (this.options.returnBuffers) { 125 | return this._buffer.slice(start, end); 126 | } else { 127 | return this._buffer.toString(this._encoding, start, end); 128 | } 129 | } else if (type === 42) { // * 130 | offset = this._offset; 131 | packetHeader = new Packet(type, this.parseHeader()); 132 | 133 | if (packetHeader.size < 0) { 134 | return null; 135 | } 136 | 137 | if (packetHeader.size > this._bytesRemaining()) { 138 | this._offset = offset - 1; 139 | throw new IncompleteReadBuffer('Wait for more data.'); 140 | } 141 | 142 | var reply = [ ]; 143 | var ntype, i, res; 144 | 145 | offset = this._offset - 1; 146 | 147 | for (i = 0; i < packetHeader.size; i++) { 148 | ntype = this._buffer[this._offset++]; 149 | 150 | if (this._offset > this._buffer.length) { 151 | throw new IncompleteReadBuffer('Wait for more data.'); 152 | } 153 | res = this._parseResult(ntype); 154 | if (res === undefined) { 155 | res = null; 156 | } 157 | reply.push(res); 158 | } 159 | 160 | return reply; 161 | } 162 | }; 163 | 164 | ReplyParser.prototype.execute = function (buffer) { 165 | this.append(buffer); 166 | 167 | var type, ret, offset; 168 | 169 | while (true) { 170 | offset = this._offset; 171 | try { 172 | // at least 4 bytes: :1\r\n 173 | if (this._bytesRemaining() < 4) { 174 | break; 175 | } 176 | 177 | type = this._buffer[this._offset++]; 178 | 179 | if (type === 43) { // + 180 | ret = this._parseResult(type); 181 | 182 | if (ret === null) { 183 | break; 184 | } 185 | 186 | this.send_reply(ret); 187 | } else if (type === 45) { // - 188 | ret = this._parseResult(type); 189 | 190 | if (ret === null) { 191 | break; 192 | } 193 | 194 | this.send_error(ret); 195 | } else if (type === 58) { // : 196 | ret = this._parseResult(type); 197 | 198 | if (ret === null) { 199 | break; 200 | } 201 | 202 | this.send_reply(ret); 203 | } else if (type === 36) { // $ 204 | ret = this._parseResult(type); 205 | 206 | if (ret === null) { 207 | break; 208 | } 209 | 210 | // check the state for what is the result of 211 | // a -1, set it back up for a null reply 212 | if (ret === undefined) { 213 | ret = null; 214 | } 215 | 216 | this.send_reply(ret); 217 | } else if (type === 42) { // * 218 | // set a rewind point. if a failure occurs, 219 | // wait for the next execute()/append() and try again 220 | offset = this._offset - 1; 221 | 222 | ret = this._parseResult(type); 223 | 224 | this.send_reply(ret); 225 | } 226 | } catch (err) { 227 | // catch the error (not enough data), rewind, and wait 228 | // for the next packet to appear 229 | if (! (err instanceof IncompleteReadBuffer)) { 230 | throw err; 231 | } 232 | this._offset = offset; 233 | break; 234 | } 235 | } 236 | }; 237 | 238 | ReplyParser.prototype.append = function (newBuffer) { 239 | if (!newBuffer) { 240 | return; 241 | } 242 | 243 | // first run 244 | if (this._buffer === null) { 245 | this._buffer = newBuffer; 246 | 247 | return; 248 | } 249 | 250 | // out of data 251 | if (this._offset >= this._buffer.length) { 252 | this._buffer = newBuffer; 253 | this._offset = 0; 254 | 255 | return; 256 | } 257 | 258 | // very large packet 259 | // check for concat, if we have it, use it 260 | if (Buffer.concat !== undefined) { 261 | this._buffer = Buffer.concat([this._buffer.slice(this._offset), newBuffer]); 262 | } else { 263 | var remaining = this._bytesRemaining(), 264 | newLength = remaining + newBuffer.length, 265 | tmpBuffer = new Buffer(newLength); 266 | 267 | this._buffer.copy(tmpBuffer, 0, this._offset); 268 | newBuffer.copy(tmpBuffer, remaining, 0); 269 | 270 | this._buffer = tmpBuffer; 271 | } 272 | 273 | this._offset = 0; 274 | }; 275 | 276 | ReplyParser.prototype.parseHeader = function () { 277 | var end = this._packetEndOffset(), 278 | value = smallToString(this._buffer, this._offset, end - 1); 279 | 280 | this._offset = end + 1; 281 | 282 | return value; 283 | }; 284 | 285 | ReplyParser.prototype._packetEndOffset = function () { 286 | var offset = this._offset; 287 | 288 | while (this._buffer[offset] !== 0x0d && this._buffer[offset + 1] !== 0x0a) { 289 | offset++; 290 | 291 | if (offset >= this._buffer.length) { 292 | throw new IncompleteReadBuffer('didn\'t see LF after NL reading multi bulk count (' + offset + ' => ' + this._buffer.length + ', ' + this._offset + ')'); 293 | } 294 | } 295 | 296 | offset++; 297 | return offset; 298 | }; 299 | 300 | ReplyParser.prototype._bytesRemaining = function () { 301 | return (this._buffer.length - this._offset) < 0 ? 0 : (this._buffer.length - this._offset); 302 | }; 303 | 304 | ReplyParser.prototype.parser_error = function (message) { 305 | this.emit('error', message); 306 | }; 307 | 308 | ReplyParser.prototype.send_error = function (reply) { 309 | this.emit('reply error', reply); 310 | }; 311 | 312 | ReplyParser.prototype.send_reply = function (reply) { 313 | this.emit('reply', reply); 314 | }; 315 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --reporter spec 2 | --recursive 3 | --growl 4 | --------------------------------------------------------------------------------