【问题标题】:connect-redis connects to localhost irrespective of provided host无论提供的主机如何,connect-redis 都连接到 localhost
【发布时间】:2018-03-10 11:10:17
【问题描述】:

我有一个express 服务器,我使用connect-redisexpress-session 将会话存储到我的elasticache 实例。但应用程序仅尝试连接到 localhost。 这是错误:-

config.redisServer.host dev-xxx-site-cache.xxxxx.0001.use1.cache.amazonaws.com
listening on {"address":"::","family":"IPv6","port":8080}...
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    at Object.exports._errnoException (util.js:856:11)
    at exports._exceptionWithHostPort (util.js:879:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1062:14)

在代码中我提供了正确的主机:-

const RedisStore = require('connect-redis')(expressSession);
const redisClient = redis.createClient({ host: config.redisServer.host, port: config.redisServer.port });
redisClient.on('error', err => console.error(err));

【问题讨论】:

    标签: javascript redis node-redis express-session


    【解决方案1】:

    您的代码似乎是正确的,请确保您没有在没有主机名和端口的情况下调用createClient()

    另外,如果您的redis 需要密码,请确保您也提供了密码。

    【讨论】:

    • 我曾在其他地方使用过它。在那里提供凭据解决了这个问题。还是谢谢。
    猜你喜欢
    • 2016-12-20
    • 1970-01-01
    • 2020-02-03
    • 2022-01-13
    • 1970-01-01
    • 2019-03-13
    • 2021-12-02
    • 1970-01-01
    • 2012-12-21
    相关资源
    最近更新 更多