I am following this documentation https://hub.docker.com/r/redis/redis-stack to connect to redis with Node js. However, I keep getting this warning in my logs
redis-stack-1 | 9:M 09 Jun 2024 03:12:50.151 * <redisgears_2> Failed loading RedisAI API.
redis-stack-1 | 9:M 09 Jun 2024 03:12:50.151 * <redisgears_2> RedisGears v2.0.20, sha='9b737886bf825fe29ddc2f8da81f73cbe0b4e858', build_type='release', built_for='Linux-ubuntu22.04.aarch64', redis_version:'7.2.4', enterprise:'false'.
Following is my folder structure
Following is DockerFile
# Use the official Node.js image from the Docker Hub
FROM node:14
# Create and set the working directory inside the container
WORKDIR /usr/src/app
# Copy package.json and package-lock.json files
COPY package*.json ./
# Install the dependencies
RUN npm install
# Expose the port the app runs on
EXPOSE 3000
# Start the application
CMD ["npm", "run", "dev"]
Following is docker-compose.yml file
version: "3.6"
services:
my-node-app:
image: my-node-app
build: .
ports:
- "3000:3000"
volumes:
- .:/usr/src/app
redis-stack:
image: redis/redis-stack:latest
environment:
- REDIS_ARGS="--requirepass mypassword"
ports:
- 6379:6379
- 8001:8001
healthcheck:
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
volumes:
- redis_data:/data
volumes:
redis_data:
This is my index.js file
const express = require("express");
const redis = require("redis");
const app = express();
const port = 3000;
// Create Redis client with Docker Compose service name as hostname
const client = redis.createClient({
host: "redis-stack", // Use the service name from Docker Compose
port: 6379,
password: "mypassword", // Change this to your actual Redis password
});
client.on("connect", () => {
console.log("Connected to Redis");
// Example: Insert data into Redis after successful connection
client.set("mykey", "Hello Redis!", (err, reply) => {
if (err) {
console.error("Error setting key in Redis:", err);
} else {
console.log("Key set successfully in Redis:", reply);
}
});
});
client.on("error", (err) => {
console.error("Error connecting to Redis:", err);
});
app.get("/", (req, res) => {
res.send("Hello Docker Compose!");
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
Not sure where I am going wrong with this. Any help would be greatly appreciated.