node.JS - 无法让 Redis 工作

发布于 2024-11-04 00:08:09 字数 881 浏览 1 评论 0原文

我已经使用“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

握住我的手 2024-11-11 00:08:09

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 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

隐诗 2024-11-11 00:08:09

对于 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.

江湖彼岸 2024-11-11 00:08:09

我在 Mac 上,必须在终端中打开两个选项卡:

  • 一个用于 redis-server
  • 另一个用于 nodemon myServer.js

希望它有帮助

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文