使用redis给出错误

我通过以下链接安装了redis。 https://github.com/mranney/node_redis

并尝试

var redis = require("redis"), client = redis.createClient(); client.on("error", function (err) { console.log("Error " + err); }); client.set("string key", "string val", redis.print); client.hset("hash key", "hashtest 1", "some value", redis.print); client.hset(["hash key", "hashtest 2", "some other value"], redis.print); client.hkeys("hash key", function (err, replies) { console.log(replies.length + " replies:"); replies.forEach(function (reply, i) { console.log(" " + i + ": " + reply); }); client.quit(); }); 

并运行node test.js

给我这个错误为什么?

 Error Error: Redis connection to 127.0.0.1:6379 failed - ECONNREFUSED, Connection refused 

为什么这个错误来了? 我该怎么办?

在Node.Js中无法访问服务器之前,需要确保服务器正在运行

值得注意的是,你首先必须通过运行来安装redis服务器

sudo apt-get安装redis-server

如果它没有运行,你可以通过运行来启动它

Redis的服务器