Comparing version 1.0.3 to 1.0.4
@@ -69,3 +69,3 @@ var _ = require('lodash'); | ||
var result; | ||
var result, arg; | ||
var commandStr = '*' + (this.args.length + 1) + '\r\n$' + this.name.length + '\r\n' + this.name + '\r\n'; | ||
@@ -76,4 +76,4 @@ if (bufferMode) { | ||
for (i = 0; i < this.args.length; ++i) { | ||
var arg = this.args[i]; | ||
if (arg instanceof Buffer || arg instanceof String) { | ||
arg = this.args[i]; | ||
if (arg instanceof Buffer) { | ||
if (arg.length === 0) { | ||
@@ -87,2 +87,5 @@ resultBuffer.write('$0\r\n\r\n'); | ||
} else { | ||
if (typeof arg !== 'string') { | ||
arg = utils.toArg(arg); | ||
} | ||
resultBuffer.write('$' + Buffer.byteLength(arg) + '\r\n' + arg + '\r\n'); | ||
@@ -95,3 +98,4 @@ } | ||
for (i = 0; i < this.args.length; ++i) { | ||
result += '$' + Buffer.byteLength(this.args[i]) + '\r\n' + this.args[i] + '\r\n'; | ||
arg = (typeof this.args[i] === 'string') ? this.args[i] : utils.toArg(this.args[i]); | ||
result += '$' + Buffer.byteLength(arg) + '\r\n' + arg + '\r\n'; | ||
} | ||
@@ -98,0 +102,0 @@ } |
@@ -194,2 +194,15 @@ /** | ||
/** | ||
* Convert a non-string arg to a string | ||
* | ||
* @param {*} arg | ||
* @return {string} | ||
*/ | ||
exports.toArg = function (arg) { | ||
if (arg === null || typeof arg === 'undefined') { | ||
return ''; | ||
} | ||
return String(arg); | ||
}; | ||
var crc16 = require('./crc'); | ||
@@ -196,0 +209,0 @@ /** |
{ | ||
"name": "ioredis", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A delightful, performance-focused Redis client for Node and io.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -31,2 +31,3 @@ # ioredis | ||
[API Documentation](API.md) | ||
[Migrating from node_redis](https://github.com/luin/ioredis/wiki/Migrating-from-node_redis) | ||
@@ -33,0 +34,0 @@ # Quick Start |
@@ -47,2 +47,24 @@ describe('send command', function () { | ||
it('should support utf8', function (done) { | ||
var redis = new Redis(); | ||
redis.set(new Buffer('你好'), new String('你好')); | ||
redis.getBuffer('你好', function (err, result) { | ||
expect(result.toString()).to.eql('你好'); | ||
redis.get('你好', function (err, result) { | ||
expect(result).to.eql('你好'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should consider null as empty str', function (done) { | ||
var redis = new Redis(); | ||
redis.set('foo', null, function () { | ||
redis.get('foo', function (err, res) { | ||
expect(res).to.eql(''); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should support return int value', function (done) { | ||
@@ -49,0 +71,0 @@ var redis = new Redis(); |
@@ -106,2 +106,11 @@ var utils = require('../../lib/utils'); | ||
}); | ||
describe('.toArg', function () { | ||
it('should return correctly', function () { | ||
expect(utils.toArg(null)).to.eql(''); | ||
expect(utils.toArg(undefined)).to.eql(''); | ||
expect(utils.toArg('abc')).to.eql('abc'); | ||
expect(utils.toArg(123)).to.eql('123'); | ||
}); | ||
}); | ||
}); |
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
149925
3785
500