Redis读写_物联网平台_边缘计算网关

概述

Redis 节点 主要用于与 Redis 数据库 进行通信,允许你在流中使用 Redis 存储和检索数据。Redis 是一个高性能的键值存储数据库,广泛应用于缓存、会话管理和实时数据存储等场景。

结合日常应用,本次示例中引用了【redis-in】【redis-out】【redis-cmd】三个节点,其中【redis-in】【redis-out】主要应用于 Redis 的发布/订阅机制,在不同的服务或设备之间发送实时通知。【redis-in】可以订阅 Redis 频道,接收实时消息并触发相应的操作。【redis-out】可以以指定主题发布消息。

【redis-cmd】是一个多功能综合节点,有关redis的常用读写操作和订阅推送都能通过该节点去实现。

输入

#一般是要写入sql语句
msg.payload

输出

#一般是命令执行得到的回执信息
msg.payload

示例及其代码

准备工作:下载创建链接所需的数据库及其可视化工具

本次示例中用到的软件为:Redis + Navicat

此处为语雀内容卡片,点击链接查看:https://yunteng.yuque.com/to2an3/aiotedge-v1xdocs/dxa5dx44ly2e3us3

开启数据库远程访问并通过可视化工具练级数据库实例:

此处为语雀内容卡片,点击链接查看:https://yunteng.yuque.com/to2an3/aiotedge-v1xdocs/wtgipg3cahd103g0#UtqzY

PS:在配置redis相关节点的时候千万要匹配操作内容与命令,若是随便配置一通,可能导致node-red崩溃。

节点连接图示:

redis系列节点数据库连接配置:

#port:redis服务监听端口
#host:redis服务部署IP
#password:redis服务连接密码,默认为无,可自行修改
#db:要连接访问的数据库代号,通常是0-15

{
  "port": 6379,
  "host": "192.168.1.45",
  "password": "123456",
  "db": 0
}

redis in节点配置:

redis out节点配置:

redis cmd -SET节点配置:

redis cmd -GET节点配置:

完整演示:

此处为语雀视频卡片,点击链接查看:AIoTedge平台Redis节点.mp4
[{"id":"5ed204131106700a","type":"comment","z":"37134d776a7bea2c","name":"redis发布与订阅","info":"","x":400,"y":80,"wires":[]},{"id":"f270a5b28a0ac3ba","type":"comment","z":"37134d776a7bea2c","name":"redis读写","info":"","x":500,"y":320,"wires":[]},{"id":"5b3522252f7a8c45","type":"comment","z":"37134d776a7bea2c","name":"inject节点","info":"","x":260,"y":400,"wires":[]},{"id":"d6bd5431cb032def","type":"comment","z":"37134d776a7bea2c","name":"inject节点","info":"","x":260,"y":520,"wires":[]},{"id":"6af1738e1f7c0933","type":"comment","z":"37134d776a7bea2c","name":"inject节点","info":"","x":280,"y":220,"wires":[]},{"id":"e708c1bcc053bd7b","type":"comment","z":"37134d776a7bea2c","name":"redis cmd节点","info":"","x":510,"y":520,"wires":[]},{"id":"a92715c442588b1a","type":"comment","z":"37134d776a7bea2c","name":"redis cmd节点","info":"","x":510,"y":400,"wires":[]},{"id":"d79c3fe5337376b0","type":"comment","z":"37134d776a7bea2c","name":"redis out节点","info":"","x":530,"y":220,"wires":[]},{"id":"f467b168c3acb4ad","type":"comment","z":"37134d776a7bea2c","name":"redis in节点","info":"","x":290,"y":120,"wires":[]},{"id":"771c2ccf9595d107","type":"comment","z":"37134d776a7bea2c","name":"debug节点","info":"","x":520,"y":120,"wires":[]},{"id":"16709081fb9aaa40","type":"comment","z":"37134d776a7bea2c","name":"debug节点","info":"","x":740,"y":400,"wires":[]},{"id":"272716a35e9d7305","type":"comment","z":"37134d776a7bea2c","name":"debug节点","info":"","x":740,"y":520,"wires":[]},{"id":"e1d4c63fe2135fec","type":"redis-in","z":"37134d776a7bea2c","server":"82099e30a68fba29","command":"psubscribe","name":"","topic":"AIoTedge","obj":true,"timeout":0,"x":280,"y":160,"wires":[["3e60701d9034fba4"]]},{"id":"ff22ff08d53bb321","type":"redis-out","z":"37134d776a7bea2c","server":"82099e30a68fba29","command":"publish","name":"","topic":"AIoTedge","obj":true,"x":540,"y":260,"wires":[]},{"id":"e51eb8521c6ce480","type":"redis-command","z":"37134d776a7bea2c","server":"82099e30a68fba29","command":"SET","name":"","topic":"thingskit","params":"[]","paramsType":"json","payloadType":"json","block":false,"x":510,"y":440,"wires":[["c3ee9820d9a98e1a"]]},{"id":"6788b6dea72d3113","type":"redis-command","z":"37134d776a7bea2c","server":"82099e30a68fba29","command":"GET","name":"","topic":"thingskit","params":"[]","paramsType":"json","payloadType":"json","block":false,"x":510,"y":560,"wires":[["0e2f6eab94baddf3"]]},{"id":"6422e2e62b7acc97","type":"inject","z":"37134d776a7bea2c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"thingskit 你好","payloadType":"str","x":290,"y":440,"wires":[["e51eb8521c6ce480"]]},{"id":"c3ee9820d9a98e1a","type":"debug","z":"37134d776a7bea2c","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":440,"wires":[]},{"id":"0e2f6eab94baddf3","type":"debug","z":"37134d776a7bea2c","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":560,"wires":[]},{"id":"9c5bb2b5b146909a","type":"inject","z":"37134d776a7bea2c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":560,"wires":[["6788b6dea72d3113"]]},{"id":"eb97294049f39040","type":"inject","z":"37134d776a7bea2c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"AIoTedge 你好","payloadType":"str","x":320,"y":260,"wires":[["ff22ff08d53bb321"]]},{"id":"3e60701d9034fba4","type":"debug","z":"37134d776a7bea2c","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":160,"wires":[]},{"id":"82099e30a68fba29","type":"redis-config","name":"redis数据库连接配置","options":"{   "port": 6379,   "host": "192.168.1.45",   "password": "123456",   "db": 0 }","cluster":false,"optionsType":"json"}]
本文通过 YUQUE WORDPRESS 同步自语雀
云腾五洲-AI助理