我与socket.io和redis聊天作为商店。我的问题是,如何从套接字室检索所有的发射?聊天工作正常,只是刷新所有丢失的邮件。以下是我管理redis商店的方式。
var redis = require('redis').createClient;
var adapter = require('socket.io-redis');
var pub = redis(port, host, {});
var sub = redis(port, host, { detect_buffers: true});
io.adapter(adapter({ pubClient: pub, subClient: sub }));
答案 0 :(得分:3)
http://www.ibm.com/developerworks/library/wa-bluemix-html5chat/index.html这些文章解决了这个问题。第4步包含答案。代码:
var redis = require('redis');
var redisClient = redis.createClient(port, host);
redisClient.lpush('messages', JSON.stringify(data)); // push into redis
redisClient.lrange('messages', 0, 99, function(err, reply) {
//reply contains all messages
});