Comparing version 1.0.12 to 1.0.13
@@ -5,31 +5,35 @@ ## Changelog | ||
### v1.0.13 - April 27, 2015 | ||
* Support SORT, ZUNIONSTORE and ZINTERSTORE in Cluster. | ||
### v1.0.12 - April 27, 2015 | ||
* [ADD] Support for defining custom commands in Cluster. | ||
* [PERFORMANCE] Use native array instead of fastqueue. | ||
* Support for defining custom commands in Cluster. | ||
* Use native array instead of fastqueue for better performance. | ||
### v1.0.11 - April 26, 2015 | ||
* [ADD] Option of `showFriendlyErrorStack` for outputing friendly error stack. | ||
* Add `showFriendlyErrorStack` option for outputing friendly error stack. | ||
### v1.0.10 - April 25, 2015 | ||
* [PERFORMANCE] Improve performance for calculating slots. | ||
* Improve performance for calculating slots. | ||
### v1.0.9 - April 25, 2015 | ||
* [ADD] Support for single node commands in cluster mode. | ||
* Support single node commands in cluster mode. | ||
### v1.0.8 - April 25, 2015 | ||
* [Add] Promise support for Cluster | ||
* Add promise supports in Cluster. | ||
### v1.0.7 - April 25, 2015 | ||
* [ADD] Option `autoResubscribe` to prevent auto re-subscribe. | ||
* [ADD] Redis#end for compatibility. | ||
* [FIX] Redis.createClient(was Redis#createClient). | ||
* Add `autoResubscribe` option to prevent auto re-subscribe. | ||
* Add `Redis#end` for compatibility. | ||
* Add `Redis.createClient`(was `Redis#createClient`). | ||
### v1.0.6 - April 24, 2015 | ||
* [ADD] Support for connect timeout. | ||
* Support setting connect timeout. |
@@ -7,3 +7,2 @@ 'use strict'; | ||
var utils = require('./utils'); | ||
var commands = require('ioredis-commands'); | ||
@@ -33,31 +32,16 @@ function ClusterCommand (command, callback) { | ||
ClusterCommand.prototype.getKeys = function () { | ||
var keys = []; | ||
var i, keyStart, keyStop; | ||
var def = commands[this.name]; | ||
if (def) { | ||
switch (this.name) { | ||
case 'eval': | ||
case 'evalsha': | ||
keyStop = parseInt(this.args[1], 10) + 2; | ||
for (i = 2; i < keyStop; ++i) { | ||
keys.push(this.args[i]); | ||
} | ||
break; | ||
// TODO | ||
// case 'sort': | ||
// case 'zunionstore': | ||
// case 'zinterstore': | ||
default: | ||
keyStart = def.keyStart - 1; | ||
keyStop = def.keyStop > 0 ? def.keyStop : this.args.length + def.keyStop + 1; | ||
for (i = keyStart; i < keyStop; i += def.step) { | ||
keys.push(this.args[i]); | ||
} | ||
break; | ||
} | ||
ClusterCommand.prototype.getKeyPart = function (key) { | ||
var starPos = key.indexOf('*'); | ||
if (starPos === -1) { | ||
return key; | ||
} | ||
return keys; | ||
var hashPos = key.indexOf('->', starPos + 1); | ||
if (hashPos === 1) { | ||
return key; | ||
} | ||
return key.slice(0, hashPos); | ||
}; | ||
module.exports = ClusterCommand; |
@@ -7,2 +7,3 @@ 'use strict'; | ||
var utils = require('./utils'); | ||
var commands = require('ioredis-commands'); | ||
/** | ||
@@ -47,2 +48,8 @@ * Command instance | ||
this.promise = new Promise(function (resolve, reject) { | ||
var transformer = Command._transformer.argument[_this.name]; | ||
if (transformer) { | ||
_this.args = transformer(_this.args); | ||
} | ||
_this.stringifyArguments(); | ||
_this.resolve = _this._convertValue(resolve); | ||
@@ -56,10 +63,61 @@ if (_this.errorStack) { | ||
} | ||
var transformer = Command._transformer.argument[_this.name]; | ||
if (transformer) { | ||
_this.args = transformer(_this.args); | ||
} | ||
}).nodeify(callback); | ||
} | ||
Command.prototype.getKeys = function () { | ||
var keys = []; | ||
var i, keyStart, keyStop; | ||
var def = commands[this.name]; | ||
if (def) { | ||
switch (this.name) { | ||
case 'eval': | ||
case 'evalsha': | ||
keyStop = parseInt(this.args[1], 10) + 2; | ||
for (i = 2; i < keyStop; ++i) { | ||
keys.push(this.args[i]); | ||
} | ||
break; | ||
case 'sort': | ||
keys.push(this.args[0]); | ||
for (i = 1; i < this.args.length - 1; ++i) { | ||
if (typeof this.args[i] !== 'string') { | ||
continue; | ||
} | ||
var directive = this.args[i].toUpperCase(); | ||
if (directive === 'GET') { | ||
i += 1; | ||
if (this.args[i] !== '#') { | ||
keys.push(this.getKeyPart(this.args[i])); | ||
} | ||
} else if (directive === 'BY') { | ||
i += 1; | ||
keys.push(this.getKeyPart(this.args[i])); | ||
} else if (directive === 'STORE') { | ||
i += 1; | ||
keys.push(this.args[i]); | ||
} | ||
} | ||
break; | ||
case 'zunionstore': | ||
case 'zinterstore': | ||
keys.push(this.args[0]); | ||
keyStop = parseInt(this.args[1], 10) + 2; | ||
for (i = 2; i < keyStop; ++i) { | ||
keys.push(this.args[i]); | ||
} | ||
break; | ||
default: | ||
keyStart = def.keyStart - 1; | ||
keyStop = def.keyStop > 0 ? def.keyStop : this.args.length + def.keyStop + 1; | ||
if (keyStart >= 0 && keyStop <= this.args.length && keyStop > keyStart && def.step > 0) { | ||
for (i = keyStart; i < keyStop; i += def.step) { | ||
keys.push(this.args[i]); | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
return keys; | ||
}; | ||
/** | ||
@@ -98,5 +156,2 @@ * Convert command to writable buffer or string | ||
} else { | ||
if (typeof arg !== 'string') { | ||
arg = utils.toArg(arg); | ||
} | ||
resultBuffer.write('$' + Buffer.byteLength(arg) + '\r\n' + arg + '\r\n'); | ||
@@ -109,4 +164,3 @@ } | ||
for (i = 0; i < this.args.length; ++i) { | ||
arg = (typeof this.args[i] === 'string') ? this.args[i] : utils.toArg(this.args[i]); | ||
result += '$' + Buffer.byteLength(arg) + '\r\n' + arg + '\r\n'; | ||
result += '$' + Buffer.byteLength(this.args[i]) + '\r\n' + this.args[i] + '\r\n'; | ||
} | ||
@@ -117,2 +171,10 @@ } | ||
Command.prototype.stringifyArguments = function () { | ||
for (var i = 0; i < this.args.length; ++i) { | ||
if (!(this.args[i] instanceof Buffer) && typeof this.args[i] !== 'string') { | ||
this.args[i] = utils.toArg(this.args[i]); | ||
} | ||
} | ||
}; | ||
/** | ||
@@ -119,0 +181,0 @@ * Convert the value from buffer to the target encoding. |
@@ -35,3 +35,3 @@ 'use strict'; | ||
// Buffer.toString() is quite slow for small strings | ||
function small_toString(buf, start, end) { | ||
function smallToString(buf, start, end) { | ||
var tmp = '', i; | ||
@@ -69,3 +69,3 @@ | ||
if (end - start < 65536) { // completely arbitrary | ||
return small_toString(this._buffer, start, end); | ||
return smallToString(this._buffer, start, end); | ||
} else { | ||
@@ -94,3 +94,3 @@ return this._buffer.toString(this._encoding, start, end); | ||
// return the coerced numeric value | ||
return +small_toString(this._buffer, start, end); | ||
return +smallToString(this._buffer, start, end); | ||
} else if (type === 36) { // $ | ||
@@ -273,3 +273,3 @@ // set a rewind point, as the packet could be larger than the | ||
var end = this._packetEndOffset(), | ||
value = small_toString(this._buffer, this._offset, end - 1); | ||
value = smallToString(this._buffer, this._offset, end - 1); | ||
@@ -276,0 +276,0 @@ this._offset = end + 1; |
@@ -39,3 +39,3 @@ 'use strict'; | ||
if (err) { | ||
self.flushQueue(new Error("Ready check failed: " + err.message)); | ||
self.flushQueue(new Error('Ready check failed: ' + err.message)); | ||
return; | ||
@@ -42,0 +42,0 @@ } |
{ | ||
"name": "ioredis", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "A delightful, performance-focused Redis client for Node and io.js", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "NODE_ENV=test mocha", | ||
"test:debug": "NODE_ENV=test DEBUG=ioredis:* mocha", | ||
"test:cov": "NODE_ENV=test node ./node_modules/istanbul/lib/cli.js cover --preserve-comments ./node_modules/mocha/bin/_mocha -- -R spec", | ||
"test": "NODE_ENV=test DEBUG=ioredis:* mocha", | ||
"test:cov": "NODE_ENV=test DEBUG=ioredis:* node ./node_modules/istanbul/lib/cli.js cover --preserve-comments ./node_modules/mocha/bin/_mocha -- -R spec", | ||
"generate-docs": "jsdoc2md lib/redis.js lib/redis_cluster.js lib/commander.js > API.md", | ||
@@ -41,2 +40,3 @@ "bench": "matcha benchmark.js" | ||
"mocha": "^2.2.1", | ||
"server-destroy": "^1.0.0", | ||
"sinon": "^1.14.1" | ||
@@ -43,0 +43,0 @@ }, |
# ioredis | ||
[![Build Status](https://travis-ci.org/luin/ioredis.png?branch=master)](https://travis-ci.org/luin/ioredis) | ||
[![Build Status](https://travis-ci.org/luin/ioredis.svg?branch=master)](https://travis-ci.org/luin/ioredis) | ||
[![Test Coverage](https://codeclimate.com/github/luin/ioredis/badges/coverage.svg)](https://codeclimate.com/github/luin/ioredis) | ||
@@ -592,2 +592,12 @@ [![Dependency Status](https://david-dm.org/luin/ioredis.svg)](https://david-dm.org/luin/ioredis) | ||
# Join in! | ||
We are happy to receive bug reports, fixes, documentation enhancements, and any other improvements. | ||
# Roadmap | ||
* Transparent Key Prefixing | ||
* [Distributed Lock](http://redis.io/topics/distlock) | ||
* Connection Pooling & Read-Write Splitting | ||
# Acknowledge | ||
@@ -594,0 +604,0 @@ |
@@ -65,3 +65,3 @@ 'use strict'; | ||
cluster.testGet('foo', '{foo}2', function (err, res) { | ||
cluster.testGet('foo', '{fo}2', function (err, res) { | ||
console.log(err, res); | ||
@@ -68,0 +68,0 @@ }); |
@@ -8,6 +8,8 @@ 'use strict'; | ||
var errors = data.split('\n'); | ||
expect(errors[0].indexOf('ReplyError')).not.eql(-1); | ||
expect(errors[1].indexOf('show_friendly_error_stack.js')).not.eql(-1); | ||
process.stderr.write.restore(); | ||
done(); | ||
if (errors[0].indexOf('Unhandled') !== -1) { | ||
expect(errors[0].indexOf('ReplyError')).not.eql(-1); | ||
expect(errors[1].indexOf('show_friendly_error_stack.js')).not.eql(-1); | ||
process.stderr.write.restore(); | ||
done(); | ||
} | ||
}); | ||
@@ -14,0 +16,0 @@ redis.set('foo'); |
@@ -15,2 +15,7 @@ 'use strict'; | ||
expect(getKeys('evalsha', ['23123', 2, 'foo', 'bar', 'zoo'])).to.eql(['foo', 'bar']); | ||
expect(getKeys('sort', ['key'])).to.eql(['key']); | ||
expect(getKeys('sort', ['key', 'BY', 'hash:*->field'])).to.eql(['key', 'hash:*']); | ||
expect(getKeys('sort', ['key', 'BY', 'hash:*->field', 'LIMIT', 2, 3, 'GET', 'gk', 'GET', '#', 'Get', 'gh->f*', 'DESC', 'ALPHA', 'STORE', 'store'])).to.eql(['key', 'hash:*', 'gk', 'gh->f', 'store']); | ||
expect(getKeys('zunionstore', ['out', 2, 'zset1', 'zset2', 'WEIGHTS', 2, 3])).to.eql(['out', 'zset1', 'zset2']); | ||
expect(getKeys('zinterstore', ['out', 2, 'zset1', 'zset2', 'WEIGHTS', 2, 3])).to.eql(['out', 'zset1', 'zset2']); | ||
@@ -17,0 +22,0 @@ function getKeys(commandName, args) { |
@@ -8,4 +8,4 @@ 'use strict'; | ||
it('should flatten the args', function () { | ||
var command = new Command('get', ['foo', ['bar', ['zoo']]]); | ||
expect(command.args).to.eql(['foo', 'bar', ['zoo']]); | ||
var command = new Command('get', ['foo', ['bar', ['zoo', 'zoo']]]); | ||
expect(command.args).to.eql(['foo', 'bar', 'zoo,zoo']); | ||
}); | ||
@@ -12,0 +12,0 @@ }); |
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
185930
4149
609
9