'get and set method of redis not working in node app
Redis is connected properly but after that, it does not show the output of the code. also Redis client set name as key properly but after that, it doesn't show any error of replay as output, the same thing happen with get method.
const express = require('express');
const redis = require("redis");
const client = redis.createClient();
client.connect();
client.on("connect", (err)=>{
if(err) throw err;
else console.log("Redis Connected!");
});
const app = express();
app.get('/',(req,res)=>{
let name = req.query['name'];
client.set("name", name, (err, replay)=>{
if(err) throw err;
else console.log(replay); //ok
});
client.get("name", (err, name)=>{
if(err) throw err;
else {
console.log(`name: ${name}`);
res.send(`hello ${name}`);
}
});
});
app.listen('3000',()=>{
console.log("server at 3000.!");
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
