Redis Client ignoring configuration options set on it and trying to connect to default ip 127.0.01
Asked Answered
T

2

7

In AWS i am using ElastiCache Redis server and using node as backEnd and "promise-redis" package

this is how i am tried to do to connect to my redis server endpoint

client = redis.createClient({
        host: '**my redis primary endpoint**',
        port: 6379
    });

this worked for a while but after adding some lines of code not related to redis it gave me this error

error: connect ECONNREFUSED 127.0.0.1:6379

it seems trying to connect to the local server and ignoring the host endpoint i gave to him

and when i changed the port to any number like 6300

it gave the same error with the default port number too

error: connect ECONNREFUSED 127.0.0.1:6379

i am so confused please help !!!!

Term answered 27/3, 2021 at 9:26 Comment(2)
Does the host and port parameters hardcoded? if not, try to console.log them and check what the actual value is..Arnett
Add the "lines of code not related to redis" to your question. It will help with finding a solution.Millet
G
13

these "geniuses" changed such a significant thing in their library as the connection and didn't even give a good warning about it. I'm already silent about the fact that it is a crime to make such changes when your library in a million projects is already coded. Now you need to connect like this:

const client = redis.createClient({
  socket: {
    host,
    port
  },
  password
});

I advise you to switch to the ioredis library, there is an old api, only the client is created through new Redis ({old config})

Because in this old library ("redis"), for some reason they now require an asynchronous connect () for some functionality, without really explaining why and when it is needed, and when it is not needed. Half of the code works for me, and half does not. So, use better this:

let Redis = require('ioredis');
  const client = new Redis({
  host: '***',
  port: ****,
  password: '****'
});
Garaway answered 24/12, 2021 at 9:9 Comment(0)
M
0

Make sure the host key does not have the protocol part "http://" in it

client = redis.createClient({ 
    host: '192.168.45.34', // don't use host: 'http://192.168.45.34'
    port: 6379 
});

If you include the protocol in your host key, the redis client defaults to using localhost - 127.0.0.1

Millet answered 4/2, 2022 at 20:39 Comment(1)
I think this is an old approach, and did not worked for me, but the following approach worked. JavaScript const client = redis.createClient({ socket: { host, port }, password }); Popcorn

© 2022 - 2024 — McMap. All rights reserved.