node.JS – 不能得到redis的工作
我已经使用“npm install redis”安装了redis。 然后运行由此项目页面node_redis生成的示例代码。 我懂了
"error error: Redis connection to 127.0.0.1:6379 failed - EPERM, Operation not permitted"
我想我在这里错过了一些东西,有人能帮我指出吗? 以下是我使用的代码
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_redis是一个允许你从NodeJS访问Redis的包,就像MySQL-Python是一个可以让你从Python访问MySQL的包。 在这两种情况下,您都需要运行代码的实际数据库实例(例如Redis或MySQL)来连接。
你应该安装Redis(取决于你的操作系统会有不同的方法来做到这一点,但在OSX上,你可以运行port install redis
或在Ubuntu上,你可以运行apt-get install redis-server
或查看这里的说明http:// redis.io/download ),然后使用redis-server
命令运行该命令,该命令将在默认端口(6379)上启动一个实例。
它也看起来像这里有一些Windows版本: http : //code.google.com/p/servicestack/wiki/RedisWindowsDownload
对于Windows用户,
从这里下载redis服务器。 https://github.com/dmajkic/redis/downloads
这工作对我来说,但我仍然在寻找一种方式来主办一个Redis数据库。
我在Mac上,不得不在我的terminal打开两个选项卡:
- 一个用于
redis-server
- 其他为
nodemon myServer.js
希望能帮助到你