使用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 install redis-server 然后,如果它没有运行,则可以通过运行来启动它 Redis服务器