Merge pull request #354 from hindessm/redis-string-fix

Make more effort to stringify sensibly when storing in redis.
This commit is contained in:
Nick O'Leary 2014-08-28 14:15:53 +01:00
commit e09ac859d3
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);