2011-04-27 45 views
4

我已經使用「npm install redis」安裝了redis。然後我運行該項目頁面node_redis生成的示例代碼。我得到這個node.JS - 無法使用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(); 
}); 
+0

是'127.0.0.6379 「這個問題中的拼寫錯誤還是與錯誤信息中顯示的一樣?應該是'127.0.0.1:6379'連接到localhost上的redis。 – samplebias 2011-04-27 03:05:57

+1

只需確認:在運行代碼之前,您已在端口6379(默認端口)上的本地主機上啓動了Redis實例,對不對?如果是這樣,你是否有本地防火牆運行? – nicolaskruchten 2011-04-27 03:29:36

+0

對不起,你說的「你已經啓動了Redis實例」是什麼意思?我只是運行代碼,我得到了錯誤。我沒有防火牆。 – 2011-04-27 04:00:08

回答

12

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

+0

我試圖編譯redis,但編譯失敗。請參閱屏幕截圖以查看錯誤http://www.vietnamlist.net/pic/5849813813039661181385560_full.png – 2011-04-28 04:49:12

+0

什麼版本的編譯器正在使用? – nicolaskruchten 2011-04-28 12:34:02

+0

如果你使用的是windows,你也可以考慮使用Redis的Windows版本,而不是自己編譯它,如果你遇到問題:http://code.google.com/p/servicestack/wiki/RedisWindowsDownload – nicolaskruchten 2011-04-28 12:36:17

5

對於Windows用戶,

從這裏下載Redis的服務器。 https://github.com/dmajkic/redis/downloads

這工作對我來說,但我仍然在搜索 主辦redis數據庫的方式。

+0

非常好,那鏈接是否幫助我解決我的問題:) – roland 2012-08-20 13:45:08

0

我在Mac和在我的終端來打開兩個標籤:

  • 一爲redis-server
  • 其他的nodemon myServer.js

希望它可以幫助