提供Redis AbortError的托管DigitalOcean Redis实例

时间:2019-09-26 04:07:27

标签: node.js docker redis sails.js digital-ocean

我在数字海洋上设置了托管redis和postgres。 Digital Ocean给了我一个.crt文件,我不知道该怎么办,所以什么也没做。这可能是以下问题的根源吗?

还是我必须根据rediss协议允许docker容器到达容器之外?

我泊坞化了一个节点应用程序,然后将此容器放到我的Droplet上。我在同一区域(SFO2)中有我的Droplet和托管的Redis和Postgres。它使用以下网址连接到Redis:

url: 'rediss://default:REMOVED_THIS_PASSWORD@my-new-app-sfo2-do-user-5053627-0.db.ondigitalocean.com:25061/0',

然后我确实使用docker run运行了docker容器。

然后它给我错误:

node_redis: WARNING: You passed "rediss" as protocol instead of the "redis" protocol!

events.js:186
      throw er; // Unhandled 'error' event
      ^
AbortError: Connection forcefully ended and command aborted. It might have been processed.
    at RedisClient.flush_and_error (/opt/apps/mynewapp/node_modules/redis/index.js:362:23)
    at RedisClient.end (/opt/apps/mynewapp/node_modules/redis/lib/extendedApi.js:52:14)
    at RedisClient.onPreConnectionEnd (/opt/apps/mynewapp/node_modules/machinepack-redis/machines/get-connection.js:157:14)
    at RedisClient.emit (events.js:209:13)
    at RedisClient.connection_gone (/opt/apps/mynewapp/node_modules/redis/index.js:590:14)
    at Socket.<anonymous> (/opt/apps/mynewapp/node_modules/redis/index.js:293:14)
    at Object.onceWrapper (events.js:298:28)
    at Socket.emit (events.js:214:15)
    at endReadableNT (_stream_readable.js:1178:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on RedisClient instance at:
    at /opt/apps/mynewapp/node_modules/redis/index.js:310:22
    at Object.callbackOrEmit [as callback_or_emit] (/opt/apps/mynewapp/node_modules/redis/lib/utils.js:89:9)
    at Command.callback (/opt/apps/mynewapp/node_modules/redis/lib/individualCommands.js:199:15)
    at RedisClient.flush_and_error (/opt/apps/mynewapp/node_modules/redis/index.js:374:29)
    at RedisClient.end (/opt/apps/mynewapp/node_modules/redis/lib/extendedApi.js:52:14)
    [... lines matching original stack trace ...]
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'NR_CLOSED',
  command: 'AUTH',
  args: [ 'REMOVED_I_DONT_KNOW_IF_THIS_IS_SENSITIVE' ]

2 个答案:

答案 0 :(得分:1)

redis 协议与 rediss 不同,因为后者使用 TLS 连接。 DigitalOcean Managed Redis requires the connections to be made over TLS,因此您必须使用 rediss。但是,我找不到有关 DigitalOcean 提供的用于连接到 Managed Redis 服务的 TLS 证书的任何信息。

根据您的错误消息,我推测您正在使用 this redis package。如果是这种情况,您可以在连接字符串中传递空的 TLS 对象选项,如下所示:

const Redis = require('redis')

const host = 'db-redis.db.ondigitalocean.com'
const port = '25061'
const username = 'user'
const password = 'secret'
const url = `${username}:${password}@${host}:${port}`

const client = Redis.createClient(url, {tls: {}})

进一步阅读/来源:

  1. SSL connections arrive for Redis on Compose
  2. Connecting to IBM Cloud Databases for Redis from Node.js

答案 1 :(得分:0)

我解决了这个问题。以下是来自 config/env/production.js

的片段

套接字

对于套接字,要启用 rediss,您必须像这样通过 adapterOptions 传递所有选项:

sockets: {
  onlyAllowOrigins: ['https://my-website.com'],

  // pass in as adapterOptions so it gets through to redis-adapter
  // as i need it "rediss" but this url is not supported i get an error.
  // so i need to pass in `tls` empty object. and i see he moves things into
  // `adapterOptions` here here - https://github.com/balderdashy/sails-hook-sockets/blob/master/lib/configure.js#L128
  adapterOptions: {
    user: 'username',
    pass: 'password',
    host: 'host',
    port: 9999,
    db: 2, // pick a number
    tls: {},
  },

  adapter: '@sailshq/socket.io-redis',
},

会话

对于会话,将 tls: {} 空对象传递给配置:

session: {
  pass: 'password',
  host: 'host',
  port: 9999,
  db: 1, // pick a number not used by sockets
  tls: {},
  cookie: {
    secure: true,
    maxAge: 24 * 60 * 60 * 1000, // 24 hours
  },
},