I am running redis in docker environment with nodejs as backend, postgres as db and react as frontend. The logic is to get index value from the frontend, calculate the fibonacci number for the index and return it. The server part takes the value and publish it. The redis is subscribed and gets the value whenever the server receives it. However, each time the redis recieves the value, it shows the error. What is the reason behind it?
Code for redis.
const redis = require("redis");
const keys = require("./keys");
const redisClient = redis.createClient({
// host: keys,
// port: keys.redisPort,
// retry_strategy: () => 1000, if connection is lost, retry every sec
});
const subscriber = redisClient.duplicate();
const connectRedis = () => {
subscriber
.connect()
.then(() => console.log("redis worker connected"))
.catch((err) => console.log("err redis connection", err));
};
connectRedis();
subscriber.subscribe("insert", async (message) => {
console.log({ message });
const val = fib(parseInt(message));
redisClient.hSet("values", message, JSON.stringify(val));
});
function fib(index) {
if (!index) return;
if (index < 2) return 1;
return fib(index - 1) + fib(index - 2);
}
Error:
Anyone coming to this question after taking Docker course of Stephen Grider, use redis v3.1.2. The newer version i.e v4 has some issues connecting to the redis.
Use the command npm i redis@3.1.2