Make more effort to stringify sensibly when storing in redis.

This commit is contained in:
Mark Hindess 2014-08-26 15:28:09 +01:00
parent 2d92b44f52
commit 025e4ab6d1
1 changed files with 7 additions and 0 deletions

View File

@ -83,6 +83,13 @@ module.exports = function(RED) {
var k = this.key || msg.topic;
if (k) {
if (this.structtype == "string") {
if (Buffer.isBuffer(msg.payload)) {
msg.payload = msg.payload.toString();
} else if (typeof msg.payload === "object") {
msg.payload = JSON.stringify(msg.payload);
} else if (typeof msg.payload !== "string") {
msg.payload = ""+msg.payload;
}
this.client.set(k,msg.payload);
} else if (this.structtype == "hash") {
var r = hashFieldRE.exec(msg.payload);