我已通过以下链接安装了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
为什么会出现这个错误?我该怎么办?
答案 0 :(得分:6)
在Node.Js
中无法访问服务器之前,您需要确保服务器正在运行答案 1 :(得分:0)
值得注意的是,首先必须通过运行
来安装redis服务器sudo apt-get install redis-server
然后如果它没有运行,你可以通过运行
来启动它redis的服务器