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();
});
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();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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 /RedisWindows下载
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 runapt-get install redis-server
or check out the instructions here http://redis.io/download) and then run it with theredis-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
对于 Windows 用户,
请从此处下载 redis-server。
https://github.com/dmajkic/redis/downloads
这对我有用,但我仍在寻找
一种托管 Redis 数据库的方法。
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.
我在 Mac 上,必须在终端中打开两个选项卡:
redis-server
nodemon myServer.js
希望它有帮助
I am on mac and had to open two tabs in my terminal:
redis-server
nodemon myServer.js
Hope it helps