Home  >  Article  >  Database  >  Introduction to how pomelo connects to redis

Introduction to how pomelo connects to redis

尚
forward
2020-04-02 10:07:022570browse

Introduction to how pomelo connects to redis

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

Introduction to how pomelo connects to redis

Use redisclient-win32.x86.1.0 to view redis data

Introduction to how pomelo connects to redis

4. Close redis , pomelo displays an error message, (binding at app.js)

Introduction to how pomelo connects to redis

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!

Statement:
This article is reproduced at:oschina.net. If there is any infringement, please contact admin@php.cn delete