Gavin Siu
Gavin Siu

Reputation: 113

Problems with migrating to Redis 4.x in Node

I am trying to migrate my google cloud app engine from Redis 3.x to 4.x. However, it appears that there have been some major changes in Redis 4.x. It appears that the client no longer autoconnect and there have been some chnages to the syntax. Here's what I have run

'use strict';
import {createClient} from 'redis';

// These are just values stored in environment variables.
const REDISHOST = process.env.REDIHOST;
const REDISPORT = process.env.REDIPORT;
const REDISAUTH = process.env.REDISAUTH;

const redisClient.createClient();
redisClient.host = REDISHOST;
redisClient.port = REDISPORT;
redisclient.auth = REDISAUTH;

redisClient.on('error', (err) => console.error(`##### REDIS ERR: ${err}.`));

await redisClient.connect();

I can tell that host, port, and auth is being set in redisClient, but when I connect, it tries to connect to localhost and fails. Any idea what I am missing here?

Upvotes: 1

Views: 522

Answers (1)

Guy Royse
Guy Royse

Reputation: 4312

You need to pass the connection information in the call the createClient():

const redisClient = createClient({
  socket: {
    host: REDISHOST,
    port: REDISPORT
  },
  password: REDISAUTH
})

There are lots of options for connecting. They are all detailed in the client configuration guide.

Upvotes: 2

Related Questions