I am hosting the redis inside docker-compose:
version: "3.8"
services:
redis:
image: redis/redis-stack:latest
container_name: redis
restart: always
volumes:
- ./conf/redis.conf:/usr/local/etc/redis/redis.conf
ports:
- "6379:6379"
command:
- redis-stack-server
- /usr/local/etc/redis/redis.conf
redis.conf:
bind 127.0.0.1 -::1
protected-mode yes
port 6379
tcp-backlog 511
...
My connection script (I am running it also inside the docker container):
import { createClient } from "redis";
const redisClient = await createClient({url: "redis://default:1234@redis:6379"})
.on("error", (err) => console.log("Redis Client Error", err))
.connect();
However, I got:
Redis Client Error Error: connect ECONNREFUSED 172.18.0.2:6379
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '172.18.0.2',
port: 6379
}
What's wrong with my connection? How can I solve it?