When a server loads a Yjs instance, it must first register to the PubSub channel. When the registration is completed, the instance loads the current state from the Redis database. This way we can make sure that the Yjs instance is always aware of all updates.
Document update events are propagated using Redis PubSub. But in order to make sure that document updates arrive in the correct order (so that count is always synchronized), we create the publish event directly on the server using the following Lua script: