mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #463 from njh/redis-object
Added support for storing a msg.payload of type object in a Redis hash
This commit is contained in:
commit
f89ddb5f7a
@ -40,7 +40,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-tips">
|
<div class="form-tips">
|
||||||
If key is blank, the topic will be used as the key.<br>
|
If key is blank, the topic will be used as the key.<br>
|
||||||
If type is hash, payload should be field=value.
|
If type is hash, payload should be an object or field=value string.
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -84,12 +84,16 @@ module.exports = function(RED) {
|
|||||||
if (this.structtype == "string") {
|
if (this.structtype == "string") {
|
||||||
this.client.set(k,RED.util.ensureString(msg.payload));
|
this.client.set(k,RED.util.ensureString(msg.payload));
|
||||||
} else if (this.structtype == "hash") {
|
} else if (this.structtype == "hash") {
|
||||||
|
if (typeof msg.payload == "object") {
|
||||||
|
this.client.hmset(k,msg.payload);
|
||||||
|
} else {
|
||||||
var r = hashFieldRE.exec(msg.payload);
|
var r = hashFieldRE.exec(msg.payload);
|
||||||
if (r) {
|
if (r) {
|
||||||
this.client.hset(k,r[1],r[2]);
|
this.client.hset(k,r[1],r[2]);
|
||||||
} else {
|
} else {
|
||||||
this.warn("Invalid payload for redis hash");
|
this.warn("Invalid payload for redis hash");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (this.structtype == "set") {
|
} else if (this.structtype == "set") {
|
||||||
this.client.sadd(k,msg.payload);
|
this.client.sadd(k,msg.payload);
|
||||||
} else if (this.structtype == "list") {
|
} else if (this.structtype == "list") {
|
||||||
|
Loading…
Reference in New Issue
Block a user