我通过 expressjs 使用 node.js
我尝试将帐户存储到会话。所以,我尝试测试在 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-server
或在它前面加上 sudo (如果需要)只是在 Linux/WSL 环境中的一个小注释。如果一切顺利,您将看到 redis-server cli 消息。也可以按照@author 的建议由 sudo service redis-server status
验证。
首先在你的系统上安装 redis -
brew install redis
然后启动redis服务器-
redis-server
简单的解决方案:
只需点击一次以下推荐并再次重新启动您的服务器
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' });
码头工人-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 用户,可以使用 Chocolatey 安装 Redis
choco install redis-64
然后从运行服务器
C:\ProgramData\chocolatey\lib\redis-64\redis-server.exe
使用 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
我也有同样的问题,首先我尝试通过sudo service restart
重新启动redis-server,但问题仍然存在。然后我通过 sudo apt-get purge redis-server
删除了 redis-server
并通过 sudo apt-get install redis-server
再次安装它,然后 redis 再次工作。还值得看看位于此处 /var/log/redis/redis-server.log
的 redis 日志
我使用 ubuntu 12.04 我通过安装 redis-server 解决了这个问题
redis-server installation for ubuntu 12.04
一些配置将获得新的 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-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;已启用;供应商预设:已启用) 活动:自周三 2018-01-17 20 起活动(运行) :07:27 IST; 16 秒前 Docs: http://redis.io/documentation, man:redis-server(1) Main PID: 4327 (redis-server) CGroup: /system.slice/redis-server.service └─4327 /usr/bin/redis-server 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 服务器在 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
您与 redis 的连接失败。尝试重新启动您的 redis 服务器,然后通过运行以下 3 个命令再次启动您的客户端:
sudo service redis-server restart
redis-server
redis-cli
尝试将您的节点升级到最新版本。
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
0.4 版可能无法正常工作。
不定期副业成功案例分享
redis-server --daemonize yes
在后台运行