Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.JS - can't get redis to work

Tags:

node.js

redis

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("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();
});
like image 214
angry kiwi Avatar asked Apr 27 '11 02:04

angry kiwi


1 Answers

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

like image 108
nicolaskruchten Avatar answered Nov 15 '22 11:11

nicolaskruchten