node.js - 如何在express-request-proxy Node 包中添​​加Redis配置

标签 node.js express redis

我正在使用“express-request-proxy” Node 包为 HTTP 请求添加代理。我启用了 Redis 缓存,它在我的本地服务器上运行良好。

以下是我如何按照文档 (https://github.com/4front/express-request-proxy#caching) 中的建议在本地加载 Redis 包:

var redis = require('redis');
require('redis-streams')(redis);

但是,当我将应用程序推送到云端时,我看到以下错误:

Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379

我有云的Redis服务器详细信息,但我不太确定如何在此处配置主机、端口和密码。

有人可以对此提出建议吗?

最佳答案

我通过添加以下内容解决了这个问题:

  var redisConfig = {
            "host": "localhost",
            "port": 6379
        };
  redis.createClient(redisConfig);

它非常简单,不知道我之前是怎么错过的。

关于node.js - 如何在express-request-proxy Node 包中添​​加Redis配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44219961/

相关文章:

node.js - react 代理错误 : Could not proxy request/api/from localhost:3000 to http://localhost:8000 (ECONNREFUSED)

javascript - 调用函数并接收 JSON

node.js - 错误:property 'token' does not exist on type' () => any'

node.js - 如何在 Express 中安装应用程序

node.js - 使用 HTTPS 的套接字 IO 和 Node 给出错误 net::ERR_INSECURE_RESPONSE

javascript - 类型 '' 上不存在属性 'Request<ParamsDictionary>'

asp.net-mvc - 在 ASP.NET MVC 5 中使用远程 Redis 配置 OutputCache

javascript - 从 Elasticsearch 响应数组中删除对象

caching - PHPCR 节点和元缓存覆盖

redis - 有没有一种方法可以只使用 Lua 中大于 int 的散列中的 HGETALL 值?