Error: connect ECONNREFUSED 127.0.0.1:6739 at TCPConnectWrap.afterConnect [as oncomplete] Node.js/redis

Error: connect ECONNREFUSED 127.0.0.1:6739 at TCPConnectWrap.afterConnect [as oncomplete] Node.js/redis

我正在尝试使用带有以下代码的 redis 包连接到 redis:

const redis = require('redis')

const client = redis.createClient({
    host: '127.0.0.1',
    port: 6739
  })
}

但我收到以下错误:

Error: connect ECONNREFUSED 127.0.0.1:6739
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 6739
}

但是,我已经启动并 运行ning 了 redis,当我使用 sudo systemctl status redis 检查它的状态时,我得到:

● redis-server.service - LSB: redis-server - Persistent key-value db
     Loaded: loaded (/etc/init.d/redis-server; generated)
     Active: active (exited) since Thu 2021-11-04 17:08:10 UTC; 44min ago
       Docs: man:systemd-sysv-generator(8)
    Process: 63842 ExecStart=/etc/init.d/redis-server start (code=exited, status=0/SUCCESS)

Nov 04 17:08:10 acecom-instance-3 systemd[1]: Starting LSB: redis-server - Persistent key-value db...
Nov 04 17:08:10 acecom-instance-3 systemd[1]: Started LSB: redis-server - Persistent key-value db.

当我尝试使用 redis-cli ping 时,我得到 PONG。所以一切看起来都是正确的。我还允许通过 ufw 进行连接,这是我 运行 sudo ufw status numbered:

的输出
Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 22/tcp                     ALLOW IN    Anywhere                  
[ 2] 80/tcp                     ALLOW IN    Anywhere                  
[ 3] 443/tcp                    ALLOW IN    Anywhere                  
[ 4] 3000:5000/tcp              ALLOW IN    Anywhere                  
[ 5] 6739                       ALLOW IN    Anywhere                  
[ 6] 22/tcp (v6)                ALLOW IN    Anywhere (v6)             
[ 7] 80/tcp (v6)                ALLOW IN    Anywhere (v6)             
[ 8] 443/tcp (v6)               ALLOW IN    Anywhere (v6)             
[ 9] 3000:5000/tcp (v6)         ALLOW IN    Anywhere (v6)             
[10] 6739 (v6)                  ALLOW IN    Anywhere (v6)

我关注了这个 docs,其他一些您可能认为重要的细节:

OS: Ubuntu 20.04.3 LTS aarch64
Node: v16.13.0
pm2: v5.1.2
redis: v3.1.2

正如 Marc 评论的那样,我的问题是我指向了错误的端口,正确的端口是 6379,而不是 6739。我可以通过 运行 sudo lsof -nP -iTCP -sTCP:LISTEN[ 找到 redis 使用的端口=11=]