diff --git a/index.js b/index.js index f35dd1b6a5..b88c1ed4fb 100644 --- a/index.js +++ b/index.js @@ -805,7 +805,7 @@ RedisClient.prototype.send_command = function (command, args, callback) { 'Please handle this in your code to make sure everything works as you intended it to.' ); args_copy[i] = 'null'; // Backwards compatible :/ - } else { + } else if (Buffer.isBuffer(args[i])) { args_copy[i] = args[i]; command_obj.buffer_args = true; big_data = true; @@ -813,6 +813,13 @@ RedisClient.prototype.send_command = function (command, args, callback) { this.pipeline += 2; this.writeDefault = this.writeBuffers; } + } else { + this.warn( + 'Deprecated: The ' + command.toUpperCase() + ' command contains a argument of type ' + args[i].constructor.name + '.\n' + + 'This is converted to "' + args[i].toString() + '" by using .toString() now and will return an error from v.3.0 on.\n' + + 'Please handle this in your code to make sure everything works as you intended it to.' + ); + args_copy[i] = args[i].toString(); // Backwards compatible :/ } } else if (typeof args[i] === 'undefined') { this.warn( diff --git a/test/commands/hset.spec.js b/test/commands/hset.spec.js index bd5415189c..d87f4d04ce 100644 --- a/test/commands/hset.spec.js +++ b/test/commands/hset.spec.js @@ -45,22 +45,22 @@ describe("The 'hset' method", function () { }); }); - it('throws a error if someone passed a array either as field or as value', function (done) { + it('warns if someone passed a array either as field or as value', function (done) { var hash = "test hash"; var field = "array"; // This would be converted to "array contents" but if you use more than one entry, // it'll result in e.g. "array contents,second content" and this is not supported and considered harmful var value = ["array contents"]; - try { - client.HMSET(hash, field, value); - throw new Error('test failed'); - } catch (err) { - if (/invalid data/.test(err.message)) { - done(); - } else { - done(err); - } - } + client.on('warning', function (msg) { + assert.strictEqual( + msg, + 'Deprecated: The HMSET command contains a argument of type Array.\n' + + 'This is converted to "array contents" by using .toString() now and will return an error from v.3.0 on.\n' + + 'Please handle this in your code to make sure everything works as you intended it to.' + ); + done(); + }); + client.HMSET(hash, field, value); }); it('does not error when a buffer and date are set as values on the same hash', function (done) {