Redis unable to connect with env port

Viewed 504

I'm trying to create a Redis client. However whenever I do:

const REDIS_PORT = process.env.PORT || 6379;

const client = redis.createClient(REDIS_PORT);

I get AbortError: Ready check failed: Fatal error encountered. Command aborted. It might have been processed.

However if I do:

const REDIS_PORT = 6379;
    
const client = redis.createClient(REDIS_PORT);

It connects properly. Why do I get this error when I put process.env.PORT?

1 Answers

Assign the desired value to the port key, use this code for create client

redis.createClient({port : REDIS_PORT})

you can check the documentation

const redis = require('redis');
const client = redis.createClient({
    host: '127.0.0.1',
    port: <port>
});
Related