I assume you have 100 installed the correct way using one of these 101(I used the top one).
雷迪斯
我会使用redis作为数据库.首先,它真的是fast,持续的.你需要安装它,但这真的很容易.
make
雷迪斯-cli
接下来你应该自己玩redis.我建议你在Simon Willison分钟前阅读这篇优秀的教程.他和我还建议你只需玩redis-cli
就可以了解数据库.
雷迪斯 client
最后,您需要安装一个redis客户端.我建议您使用mranney's node_redis,因为我认为它是开发速度最快、最活跃的客户.
Installation
npm install hiredis redis
Simple example, included as example.js:
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();
});
在数据库中存储会话
此外,express的作者还创建了一个库,用于使用redis处理您的sessions.
Installation:
npm install connect-redis
Example:
var connect = require('connect')
, 雷迪斯Store = require('connect-redis');
connect.createServer(
connect.cookieDecoder(),
// 5 minutes
connect.session({ store: new 雷迪斯Store({ maxAge: 300000 }) })
);
在数据库中存储消息
我想我会用sorted set来做这个.使用ZADD
存储消息,使用ZRANK
ZRANGEBYSCORE
检索消息.
插座木卫一
最后,如果你想创建一个简单的聊天,我建议你看看socket.伊奥.
插座io的目标是制作实时应用程序
我还使用socket创建了一个聊天室.我在stackoverflow上发布的io.添加持久性+身份验证应该是轻而易举的事.