I need some help with the following scenario: I am using redis to store chat messages sent to various rooms:
for(var i = 0; i < 5; i++){
var message = {
"player": "player " + i,
"message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque convallis finibus bibendum. Praesent quis ante vitae est porttitor scelerisque. Vestibulum blandit, urna ac placerat vehicula, orci nunc bibendum sem, vitae condimentum orci purus id nisi.",
"room": "room-1",
"time": new Date()
};
client.lpush(1room-1', JSON.stringify(message), redis.print);
}
I then fetch the last 100 messages:
var args = [ 'room-1', '0', '100' ];
client.lrange(args, function(err, results){
if(err){
console.log(err);
} else {
_.each(results, function(result){
var message = JSON.parse(result);
console.log(message);
});
}
});
I am new to redis and would like to make sure this is the best way of writing and reading for the scenario. I am concerned about the need to stringify the object for write and then parse the reads.
Is this the optimal way of doing this?