Redis Client Error Error: connect ECONNREFUSED 127.0.0.1:6379

84 views Asked by At

I am attempting to connect to ElastiCache from my Koa-based Node.js application, which is deployed on an EC2 instance. Initially, the application successfully establishes a connection to the Redis instance. However, later on, the application attempts to connect to localhost, i.e., 127.0.0.1:6379.

Redis version: 7.x Redis npm package: 4.x

Error: info: Redis Connected Successfully

Redis Client Error Error: connect ECONNREFUSED 127.0.0.1:6379 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 6379 } Redis Client Error Error: connect ECONNREFUSED 127.0.0.1:6379 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 6379 } events.js:377 throw er; // Unhandled 'error' event ^

Error: ENOENT: no such file or directory, open '/home/ec2-user/logs/logs.log'

Emitted 'error' event on instance at: at WriteStream. (/home/ec2-user/uc-server/node_modules/winston/lib/winston/transports/file.js:490:16) at WriteStream.emit (events.js:400:28) at WriteStream.emit (domain.js:475:12) at internal/fs/streams.js:335:14 at FSReqCallback.oncomplete (fs.js:179:23) { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/ec2-user/logs/logs.log' }

App.js:

const { createClient } = require('redis');
const session = require('koa-session');

app.keys = [CONFIG.APP_CONFIG.KEY]
console.log("REDIS HOST: ", REDIS_HOST, REDIS_PORT, CONFIG.REDIS_AUTH);
const client = createClient({url: `redis://:@${REDIS_HOST}:${REDIS_PORT}`});
app.use(session({
  store: {
    async get(key) {
      return await client.get(key);
    },
    async set(key, value) {
      return await client.set(key, value);
    },
    async destroy(key) {
      return await client.del(key);
    }
  },
  cookie: { domain: process.env.LOCAL_DOMAIN ? 'localhost': 'xxx.com', maxAge: 15552000/* , path: "/api" */ },
  key: '_09dfbb',
  maxAge: 15552000,
  renew: true,
  ttl: 15552000,
  rolling: false
}, app))
0

There are 0 answers