From afde3d0ab8bb61ff470f1fa6f5b6ef69218b2163 Mon Sep 17 00:00:00 2001 From: Nicholas Humfrey Date: Thu, 30 Oct 2014 10:09:40 +0000 Subject: [PATCH] Added support for storing a msg.payload of type object in a Redis hash --- nodes/core/storage/65-redisout.html | 2 +- nodes/core/storage/65-redisout.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/nodes/core/storage/65-redisout.html b/nodes/core/storage/65-redisout.html index 9000dfd69..dc1f7b838 100644 --- a/nodes/core/storage/65-redisout.html +++ b/nodes/core/storage/65-redisout.html @@ -40,7 +40,7 @@
If key is blank, the topic will be used as the key.
- If type is hash, payload should be field=value. + If type is hash, payload should be an object or field=value string.
diff --git a/nodes/core/storage/65-redisout.js b/nodes/core/storage/65-redisout.js index 907e2a558..3d3be1bb8 100644 --- a/nodes/core/storage/65-redisout.js +++ b/nodes/core/storage/65-redisout.js @@ -84,11 +84,15 @@ module.exports = function(RED) { if (this.structtype == "string") { this.client.set(k,RED.util.ensureString(msg.payload)); } else if (this.structtype == "hash") { - var r = hashFieldRE.exec(msg.payload); - if (r) { - this.client.hset(k,r[1],r[2]); + if (typeof msg.payload == "object") { + this.client.hmset(k,msg.payload); } else { - this.warn("Invalid payload for redis hash"); + var r = hashFieldRE.exec(msg.payload); + if (r) { + this.client.hset(k,r[1],r[2]); + } else { + this.warn("Invalid payload for redis hash"); + } } } else if (this.structtype == "set") { this.client.sadd(k,msg.payload);