gpt4 book ai didi

Node.js 和 Redis 身份验证

转载 作者:IT老高 更新时间:2023-10-28 23:08:39 25 4
gpt4 key购买 nike

我没有获得使用 redis auth 的 redis node.js 文档。

每个例子:

var redis = require("redis"),
client = redis.createClient();

// This command is magical. Client stashes the password and will issue on every connect.
client.auth("somepass");

在我的代码中,我有以下内容:

var redis = require("redis");
r = redis.createClient(6379,'xxx.xxx.xxx.xxx');
r.auth("yyyyyyyy");

app.get('/', function(req, res){
r.set("foo", 'bar');
res.writeHead(200, {'Content-Type': 'image/gif'});
res.end('Hello');
});

这是我得到的错误:

    Express server listening on port 8070 in development mode

/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/redis/index.js:468
throw callback_err;
^
Error: Auth error: Error: ERR Client sent AUTH, but no password is set
at Command.callback (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/redis/index.js:163:43)
at RedisClient.return_error (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/redis/index.js:464:25)
at HiredisReplyParser.<anonymous> (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/redis/index.js:253:14)
at HiredisReplyParser.emit (events.js:67:17)
at HiredisReplyParser.execute (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/redis/lib/parser/hiredis.js:41:18)
at RedisClient.on_data (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/redis/index.js:440:27)
at Socket.<anonymous> (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/redis/index.js:70:14)
at Socket.emit (events.js:67:17)
at TCP.onread (net.js:367:14)
[7]+ Killed node app.js 8070

那么,正确的身份验证方法是什么?

最佳答案

此问题的另一个原因可能是在启动 redis-server 时未指定您的 redis.conf(如果您在其中输入“requirepass”)。

在这种情况下,redis 服务器以默认配置启动(即未启用“requirepass”选项),因此不接受您的 AUTH 命令。

./src/redis-server redis.conf

关于Node.js 和 Redis 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10667056/

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