gpt4 book ai didi

node.js - Redis报错: Error: Redis connection to 127. 0.0.1 :6379 failed - connect ECONNREFUSED 127. 0.0.1:6379

转载 作者:可可西里 更新时间:2023-11-01 11:17:57 28 4
gpt4 key购买 nike

当我检查我的 redis-server 状态时,它说 redis 服务器正在运行,但我在登录时收到此错误RedisClient.on('错误', function(err) {console.log('Redis error: ' + err);//Redis 错误: Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379});当我尝试控制 req.session 时,它返回未定义。关于这个问题的任何线索?请帮助我,我是新来的。谢谢

这是我的设置:

var express = require('express');
var redis = require("redis");
var session = require('express-session');
var redisStore = require('connect-redis')(session);
var parser = require('body-parser');
var RedisClient= redis.createClient();

app.use(session({
secret: 'myseceret',
store: new redisStore({host: '127.0.0.1', port: 6379, client: client,ttl : 260}),
saveUninitialized: false,
resave: false,
cookie: { secure: true }
}));
client.on('error', function(err) {
console.log('Redis error: ' + err);
});

最佳答案

您在 redisStore 的选项中一起提供了互斥参数。您要么传递主机和端口,要么只传递现有的 Redis 客户端。

引用 connect-redis文档-

A Redis client is required. An existing client can be passed directly using the client param or created for you using the host, port, or socket params

还有一些引用错误,我已在此片段中更正。

var express = require('express');
var redis = require("redis");
var session = require('express-session');
var redisStore = require('connect-redis')(session);
var parser = require('body-parser');
var RedisClient= redis.createClient();

var app = express();

app.use(session({
secret: 'mysecret',
store: new redisStore({client: RedisClient,ttl : 260}),
saveUninitialized: false,
resave: false,
cookie: { secure: true }
}));

RedisClient.on('error', function(err) {
console.log('Redis error: ' + err);
});

RedisClient.on("ready",function () {
console.log("Redis is ready");
});

关于node.js - Redis报错: Error: Redis connection to 127. 0.0.1 :6379 failed - connect ECONNREFUSED 127. 0.0.1:6379,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42290343/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com