Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

hmset throws/errors out on non-string values. fixes #218

  • Loading branch information...
commit b60e001fa08403240a6ecbf0c36d1c08ed8ccd9d 1 parent 7734fb6
@DTrejo DTrejo authored
Showing with 24 additions and 1 deletion.
  1. +1 −1  README.md
  2. +5 −0 index.js
  3. +18 −0 test.js
View
2  README.md
@@ -277,7 +277,7 @@ Output:
Multiple values in a hash can be set by supplying an object:
client.HMSET(key2, {
- "0123456789": "abcdefghij",
+ "0123456789": "abcdefghij", // NOTE: the key and value must both be strings
"some manner of key": "a type of value"
});
View
5 index.js
@@ -898,6 +898,11 @@ RedisClient.prototype.hmset = function (args, callback) {
for (i = 0, il = tmp_keys.length; i < il ; i++) {
key = tmp_keys[i];
tmp_args.push(key);
+ if (typeof args[1][key] !== "string") {
+ var err = new Error("hmset expected value to be a string", key, ":", args[1][key]);
+ if (callback) return callback(err);
+ else throw err;
+ }
tmp_args.push(args[1][key]);
}
args = tmp_args;
View
18 test.js
@@ -1348,6 +1348,24 @@ tests.OPTIONAL_CALLBACK_UNDEFINED = function () {
client.get("op_cb2", last(name, require_string("y", name)));
};
+tests.HMSET_THROWS_ON_NON_STRINGS = function () {
+ var name = "HMSET_THROWS_ON_NON_STRINGS";
+ var hash = name;
+ var data = { "a": [ "this is not a string" ] };
+
+ client.hmset(hash, data, cb);
+ function cb(e, r) {
+ assert(e); // should be an error!
+ }
+
+ // alternative way it throws
+ function thrower() {
+ client.hmset(hash, data);
+ }
+ assert.throws(thrower);
+ next(name);
+};
+
// TODO - need a better way to test auth, maybe auto-config a local Redis server or something.
// Yes, this is the real password. Please be nice, thanks.
tests.auth = function () {
Please sign in to comment.
Something went wrong with that request. Please try again.