1
votes

I've 2 ideas.

Idea #1:

Using Redis put people currently online into set. Then from client side user would periodically send a request to send him status for all of his friends. Server would make sql request to get all friends and find them in the redis set and if so then they are online.

Idea #2:

Using Redis PubSub, when you as a user are online you subscribe to all n friend channels. And whenever a user goes online he publishes on a channel that he or she is online. And whoever maybe listening will get notified.

Now I can't tell which one is more scalable and efficient.

1

1 Answers

1
votes

I think idea #1 should be the solution. idea #2 CANNOT work.

Redis doesn't keep published messages. So if a client is NOT connecting to Redis, the message will be lost. When he reconnects to Redis, he won't receive any messages published before.

In your case of idea #2, when a user logs in, he has no idea whether his friends are already online. Because his online friends have published online messages before he logs in, and he won't get these messages.