How to connect pomelo to redis:
1. Add code to app.js
var redis = require("redis"); var client = redis.createClient(6379, "127.0.0.1", {}); // 连接 client.on("error", function (err) {///绑定redis数据库错误回调 console.error("Redis:Error:" + err); }); app.set("redis", client); // app访问接口
2. Add code to GoodsService.js
var redis= app.get("redis");//获得 redis 对象 redis.set("name", "caoshanshan", function (err, rep) { //插入数据 console.log("Redis:" + rep);//回调 });
3. Test
Use redisclient-win32.x86.1.0 to view redis data
4. Close redis , pomelo displays an error message, (binding at app.js)
Related recommendations:
mysql video tutorial: https: //www.php.cn/course/list/51.html
The above is the detailed content of Introduction to how pomelo connects to redis. For more information, please follow other related articles on the PHP Chinese website!