2013-08-26 19 views
-1

Helo傢伙我只是新的nodejs和redis,但我沒有任何想法在redis中使用nodejs/express插入數據。你能幫我或給我一個例子嗎?感謝:*如何使用NodeJs在Redis中插入數據?

〜janella :)

+0

的https: //github.com/mranney/node_redis – sachin

+0

https://npmjs.org/package/redis –

回答

2

您可以使用最流行的(至少目前如此)客戶端模塊:redis

(來自文件)

var redis = require("redis"), 
    client = redis.createClient(); 

// if you'd like to select database 3, instead of 0 (default), call 
// client.select(3, function() { /* ... */ }); 

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

聽起來就像你需要查看HTML表單和HTTP REST,html表單將數據發送到Express服務器。快遞服務器將註冊一個路由,在該路由中您將添加數據到redis。 'app.post(「/ route」,req,res,next(){// redis code here}' – djbrick

+1

看起來你需要完整的工作解決方案,所以可能stackoverflow不是正確的地方。 –

相關問題