Lakshan Perera implemented a real-time collaborative editor using Redis PUB/SUB support which will become available with Redis 2.0 announced for May 21st and currently available as RC1, Node.js and web sockets. Redis is also used for storing the documents in the app.
On each pad, there are different types of messages that users send on different events. These messages needs to be propagated correctly to other users.
Mainly following messages needs to be sent:
- When a user joins a pad
- When a user leaves a pad
- When a user sends a diff
- When a user sends a chat message
For handling the message delivery, I used Redis’ newly introduced pub/sub implementation. Every time a user is connected (i.e. visits a pad) there would be two redis client instances initiated for him. One client is used for publishing his messages, while other will be used to listen to incoming messages from subscribed channels.
Source code of the project can be found on ☞ GitHub and there’s also a short video demo of the app:
Just in case you are wondering about the Node.js-Redis combination, Michael Bleigh’s presentation below will detail some of the benefits of using the asynchronous model:
Last, but not least, I should say that Node.js usage is not at all common in the NoSQL world.