Cloud9 IDE上的Nodejs中的Redis:

这是我的代码:

var express = require("express"), app = express(), server = require("http").createServer(app), io = require("socket.io").listen(server), redis = require("redis"), env = {PORT: process.env.PORT || 8080, IP: process.env.IP || "localhost"}; client = redis.createClient(env.PORT , env.IP); client.on("error", function(err) { console.log(err); }); server.listen(env.PORT); console.log("Server started @ " + env.IP + ":" + env.PORT); 

试图运行后,我在控制台上收到以下信息:

 Running Node Process Your code is running at 'http://modified.address.c9.io'. Important: use 'process.env.PORT' as the port and 'process.env.IP' as the host in your scripts! info: socket.io started Server started @ modified.ip.address.1:8080 [Error: Auth error: undefined] 

我试图build立连接,并完全连接到IP和端口。 但是,出现错误[Error: Auth error: undefined]并在此处停止。 我GOOGLE了错误,从我使用的IDE支持…,令人惊讶的是,只有7个链接到我的问题。 所以我认为这可能是我的一个漏洞,或者这不是一个真正的问题,但我不知道要解决这个问题。 所有我可以从这些谷歌结果退出(我不知道),我需要创build它后立即使用client.auth(pass) 。 但是,我应该在哪里find密码? 当我安装它npm install redis我没有configuration任何东西,并没有告诉设置任何密码。 所以我陷入了僵局。

我使用Cloud9 IDE(c9.io),以及上面代码中使用的模块。

—-最诚挚的问候—-蒂姆。

我发现什么是错的。

我确实安装了Redis,但这是一个Redis库,它像Redis驱动程序和NodeJS之间的桥梁。 在Cloud9上,我也必须手动安装Redis。

所以需要2个命令来实际安装Redis:

在Cloud9上安装Redis驱动程序

 nada-nix install redis 

安装NodeJS的Redis库

 npm install redis 

感谢任何试图帮助我的人。

您可以使用自己的configuration文件运行redis服务器。您可以创build自己的configuration,如下所示。

  //port and ip of ur redis server port 6371 bind 127.0.0.1 //password for this server requirepass ucanmentionurpwd //storing snapshots of the data save 60 1 dbfilename dump.rdb dir /tmp/db //starting redis server redis-server //ur config file location 

请参阅此链接了解redisconfigurationhttps://raw.github.com/antirez/redis/2.6/redis.conf

如果你提到你的密码requirepass只意味着你需要做的

  client.auth('urPwd'); 

否则,不需要调用client.auth方法。