0

I have looked at this question: How to start redis-server on a different port than the default port 6379 in ubuntu I'm trying to do just that via ioredis in my NestJS project, but it refuses to connect to any other port than 6379. I'm not running any separate Redis Server, I leave that to ioredis. It's just that I want to run a separate instance for Testing purposes that does not run on port 6379.

The following code runs without error:

const redis = new Redis();
const redis = new Redis('localhost');
const redis = new Redis(6379);

And I can do everything I need to with this.

This code, however:

const redis = new Redis(6380);
const redis = new Redis(6380, 'localhost');

gives me the following error:

[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6380
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)

Do I have to use different ioredis instantiation options? Or is it maybe something with NestJS? Because I am aware that NestJS has a page on Redis: https://docs.nestjs.com/microservices/redis , but they also specify port 6379. How come I cannot seem to get the basic example in the ioredis API documentation working?

CoderApprentice
  • 425
  • 1
  • 6
  • 21
  • I'm confused or i'm missing something...isn't `ioredis` a client? If so, and if the client is saying it can't connect to a server in port `6380` is because there isn't a server running in that port. Did you start one? – nitrin0 Sep 13 '21 at 11:40
  • @nitrin0 I did not start a server, but ioredis apparently does this automatically at port 6379. So I'm wondering why that port, but not any other port. – CoderApprentice Sep 13 '21 at 12:13
  • 1
    Are you talking about [this ioredis](https://www.npmjs.com/package/ioredis)? It's a client, not a server. It won't start a server for you. When you do `new Redis(6380, "127.0.0.1")` you are creating a client that connects to a server running on `127.0.0.1:6380`, not creating a server. You are able to connect to the default port (6379) because you probably installed a redis server and it's running. – nitrin0 Sep 13 '21 at 12:18
  • @nitrin0 Yea that ioredis, I installed it with npm through package.json: `"ioredis": "^4.27.9"` . I don't have redis installed separately, just ioredis in this specific NestJS project. I just deleted the entire node_modules map and reinstalled, I restarted the desktop, and in my test it's still connecting to that Redis Server... – CoderApprentice Sep 13 '21 at 12:59
  • @nitrin0 You're right though, if I start my NestJS project with `npm run start` and set my MicroService to port 6379, it says that port is already in use. – CoderApprentice Sep 13 '21 at 13:02
  • @nitrin0 Okay I restarted my PC and immediately executed `sudo netstat -tulpn | grep LISTEN` : tcp6 0 0 :::6379 :::* LISTEN 1698/docker-proxy There just happens to be a docker server running at that port I guess... just wondering how I was able to store and retrieve data with it through ioredis... – CoderApprentice Sep 13 '21 at 13:23
  • 1
    You were able to do so because `new Redis()`, `new Redis("localhost")` and `new Redis(6379)` all are able to connect to it. You seem to have a redis instance running via docker, exposing port 6379. – nitrin0 Sep 13 '21 at 13:28
  • @nitrin0 Well this is embarrassing. Thanks for your time, guess I'll answer this question by explaining what we discussed here. – CoderApprentice Sep 13 '21 at 13:34
  • No problem m8, we're all here to learn something :) – nitrin0 Sep 13 '21 at 13:36

1 Answers1

0

It would appear there was already a redis docker instance running on the local network on :::6379, taking up that port number for any address, outside my knowledge... This is quite an embarrassing answer to the question, however the question is wrong anyway so why not keep at it.

ioredis does not start a Server for you, it is only a Client. Since my tests succeeded, I assumed ioredis was starting a server as well, but it was all a huge misunderstanding.

CoderApprentice
  • 425
  • 1
  • 6
  • 21