Keep chat history with socket.io-redis -
i have chat socket.io , redis store. question is, how can retrieve emits socket room? chat working, on refresh messages lost. below how manage redis store.
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 }));
http://www.ibm.com/developerworks/library/wa-bluemix-html5chat/index.html article solve problem. step 4 contain answer. code:
var redis = require('redis'); var redisclient = redis.createclient(port, host); redisclient.lpush('messages', json.stringify(data)); // push redis redisclient.lrange('messages', 0, 99, function(err, reply) { //reply contains messages });
Comments
Post a Comment