简体   繁体   中英

Encountering "Error: connect ECONNREFUSED 127.0.0.1:6379..." when running Google Cloud Function connecting to a Redis Instance

Im running a function to ingest data to a Redis instance. However, I am encountering an issue where I can't seem to connect to the client.

Here is the part of the code where it connects to the server.

const redis = require('redis');
require('dotenv').config;

        const REDISHOST = process.env.REDISHOST;
        const REDISPORT = 6379;
        const REDISAUTH = process.env.AUTHSTRING;

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

        await client.connect();

Here is the whole error message:

"Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16)
    at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17)"

Any help would be appreciated. Thanks

I have tried using ioredis instead of redis but it shows a different error altogether.

It's trying to connect to localhost and Redis doesn't exist there. IF not given a hostname, this is the default behavior of Redis.

Looking at your code, this is probably because the REDISHOST environment variable isn't defined.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM