使用redis给出错误

XMe*_*Men 4 redis node.js

我通过以下链接安装了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();
});
Run Code Online (Sandbox Code Playgroud)

并运行 node test.js

给我这个错误为什么?

Error Error: Redis connection to 127.0.0.1:6379 failed - ECONNREFUSED, Connection refused
Run Code Online (Sandbox Code Playgroud)

为什么会出现这个错误?我该怎么办?

Col*_*lum 6

您需要确保服务器正在运行,然后才能在Node.Js中访问它