簡體   English   中英

Redis 連接到 127.0.0.1:6379 失敗 - 連接 ECONNREFUSED

[英]Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED

我通過 expressjs 使用 node.js
我嘗試將帳戶存儲到 session。 所以,我嘗試測試使用 session 和expressjs中的代碼

var RedisStore = require('connect-redis')(express);
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: "keyboard cat", store: new RedisStore }));

但我收到錯誤Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
請幫我解決這個問題

安裝 redis 后,從終端輸入:

redis-server

你會運行redis

我用下一個方法解決這個問題:

sudo apt-get install redis-server

然后運行命令以確認一切正常:

sudo service redis-server status

輸出將是: redis-server is running - 這意味着問題已解決。

首先在您的系統上安裝 redis -

brew install redis

然后啟動redis服務器——

redis-server

我在 Windows 上,必須從這里安裝 Redis,然后運行redis-server.exe

這個 SO 問題的頂部開始。

簡單的解決方案:

只在下面點贊一次,然后再次重啟你的服務器

redis-server

對於 Windows 用戶,可以使用 Chocolatey 來安裝 Redis

choco install redis-64

然后從運行服務器

C:\ProgramData\chocolatey\lib\redis-64\redis-server.exe

我也有同樣的問題,首先我嘗試通過sudo service restart啟動 redis-server 但問題仍然存在。 然后我通過sudo apt-get purge redis-server刪除了redis-server並通過sudo apt-get install redis-server再次安裝它,然后 redis 再次工作。 還值得看看位於這里的 redis 日志/var/log/redis/redis-server.log

使用 Windows 10? 去這里: https : //docs.microsoft.com/en-us/windows/wsl/wsl2-install

然后跑...

    $ wget https://github.com/antirez/redis/archive/5.0.5.tar.gz <- change this to whatever Redis version you want (https://github.com/antirez/redis/releases)
    $ tar xzf redis-5.0.5.tar.gz
    $ cd redis-5.0.5
    $ make

我使用的是 ubuntu 12.04 我通過安裝 redis-server 解決了這個問題

ubuntu 12.04 的 redis-server 安裝

一些配置將新的 root 權限還列出了其他操作系統的手冊

謝謝

對於 windows 平台,您必須檢查redis-server是否在給定的 ip:port 上運行。 您可以在安裝目錄/conf/redis.conf找到 redis 配置。 默認情況下,客戶端接受127.0.0.1:6379

我在 MBP 上,並安裝redis詳細信息我的問題已解決。修復了下載、提取和編譯 Redis 的問題:

$ wget http://download.redis.io/releases/redis-3.0.2.tar.gz

$ tar xzf redis-3.0.2.tar.gz

$ cd redis-3.0.2

$ make

現在編譯的二進制文件在 src 目錄中可用。

運行Redis:

$ src/redis-server 

您與 redis 的連接失敗。 嘗試重新啟動您的 redis 服務器,然后通過運行以下 3 個命令再次啟動您的客戶端:

sudo service redis-server restart
redis-server
redis-cli

我想也許你是通過源代碼安裝了 redis。如果你需要找到 redis-source-code-path/utils 並運行sudo install_server.sh命令。 之后,確保 redis-server 已作為您系統的服務運行sudo service redis-server status

PS:基於Debian/Ubuntu

在 ubuntu 的情況下,錯誤是由於未設置 redis-server。 再次安裝redis-server,然后檢查狀態。

如果沒有錯誤,則會顯示這樣的消息:-

● redis-server.service - 高級鍵值存儲已加載:已加載(/lib/systemd/system/redis-server.service;已啟用;供應商預設:已啟用) Active:自 2018-01-17 20 星期三以來處於活動狀態(正在運行) :07:27 IST; 16s ago Docs: http://redis.io/documentation , man:redis-server(1) Main PID: 4327 (redis-server) CGroup: /system.slice/redis-server.service └─4327 /usr/bin /redis-服務器 127.0.0.1:6379

你必須先安裝redis服務器;

您可以按照以下步驟在 mac 上安裝 redis 服務器 -

  $ curl -O http://download.redis.io/redis-stable.tar.gz
  $ tar xzvf redis-stable.tar.gz
  $ cd redis-stable
  $ make
  $ make test
  $ sudo make install
  $ redis-server

祝你好運。

對我來說,我在 Ubuntu 18.x 上遇到了這個問題,但我的問題是我的 redis-server 在 127.0.0.1 上運行,但我發現我需要在我的 IP 地址 xxx.xx.xx.xx 上運行它

我進入我的 Ubuntu 機器並執行以下操作。

cd /etc/redis/

sudo vim redis.conf

然后我編輯了這部分。

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).le to listen to just one or multiple selected interfaces using
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# bind 127.0.0.1 ::1 10.0.0.1
bind 127.0.0.1 ::1 # <<-------- change this to what your iP address is something like (bind 192.168.2.2)

保存,然后重新啟動 redis-server。

sudo service redis-server restart或簡單地運行redis-server

對於那些將 docker 與 docker-compose 和 Typescript 一起使用的人,我的解決方案是

import { RedisClient } from 'redis';

 const pubClient = new RedisClient({ url: 'redis://redis:6379' });

import { createClient } from 'redis';

const pubClient = createClient({ url: 'redis://redis:6379' });

docker-compose.yml

version: '3.9'

services:
  main:
    build:
      context: .
      target: development
    ports:
      - ${PORT}:${PORT}
    volumes:
      - ./src:/usr/src/app/src
      - /app/node_modules
    env_file:
      - .env
    command: npm run start:dev
    depends_on:
      - mongo
      - redis
  mongo:
    image: mongo:5.0.2-focal
    volumes:
      - mongo-data:/data/db
  mongo-express:
    image: mongo-express:0.54.0
    ports:
      - 8081:8081
    depends_on:
      - mongo
  redis:
    image: redis:6.2.5-alpine

volumes:
  mongo-data:

對於 Windows 我解決了這個問題...

使用...讓 redisClient = createClient({ legacyMode: true, url: 'redis://redis:6379', });

適用於 redis 版本 > 4.0
你可以參考下圖。

在此處輸入圖像描述

嘗試將您的節點升級到最新版本。

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

0.4 版可能無法正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM