开发者

node.JS - can't get redis to work

I have installed redis using "npm install redis". Then I run the sample code prodvided by this project page node_redis. I got this

 "error error: Redis connection to 127.0.0.1:6379 failed - EPERM, Operation not permitted"

I think I'm missing something here, can someone help me point it out? Below is the code I used

var redis = require("redis"),
    client = redis.createClient();

client.on("error", function (err){
    console.log("Error " + err);
});

client.set("strin开发者_如何学运维g 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_redis is a package which lets you access Redis from NodeJS, much like MySQL-Python is a package which lets you access MySQL from Python. In both cases you need to have an actual instance of the database (e.g. Redis or MySQL) running for your code to connect to.

You should install Redis (depending on your OS there will be different ways to do this, but on OSX you could run port install redis or on Ubuntu you could run apt-get install redis-server or check out the instructions here http://redis.io/download) and then run it with the redis-server command, which would start up an instance on the default port (6379).

It also looks like there are some Windows builds here: http://code.google.com/p/servicestack/wiki/RedisWindowsDownload


For Windows users,

download the redis-server from here. https://github.com/dmajkic/redis/downloads

this worked for me, but I am still searching on a way to host a redis database.


I am on mac and had to open two tabs in my terminal:

  • One for redis-server
  • Other for nodemon myServer.js

Hope it helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜