Search code examples
redispredis

Is there a way to associate proprieties to chat messages using Redis?


I am trying to build a chat room and I want to store additional information like: nickname, time and avatar then associate them to a message.

I might use ':' to separate between some properties but it doesn't sound like an elegant way!

$list = "message_history";
$message = $data['nickname'] . ':' . $data['message'];
Redis::lpush($list, $message);

Is there an elegant way to do so using Redis ?


Solution

  • I ended up using a hash 'hset'. And by giving each message an id and save them in a separate list I could access all the messages through that list.