.. | ||
config | ||
src | ||
test | ||
.eslintignore | ||
.eslintrc.cjs | ||
.gitignore | ||
client.js | ||
package.json | ||
README.md | ||
tsconfig.json | ||
tslint.json |
Quick Example of Syncing Automerge Docs via Redis
The good:
- store the document in redis as both a compacted document save and as individual changes
- able to load the the saved document, and then calculate which changes are missing in a single pass
- uses redis (RPUSH) to get global change ordering
- wake all clients on new changes with redis (PUBLISH, SUBSCRIBE)
- elect (via SETNX) a single leader to saveIncremental() every 10 seconds
- said node also does a full doc save when incremental bytes are 10x the base save
- detects disconnection of the leader (via EXPIRE) and elects a new leader
- detects when a document has not been created and elects a single node to create it
The bad:
- redis can do binary data - i couldnt figure it out - i hex encode/decode everything
- there's probably a few race conditions i need to find
- my typescript is ass
- not much in the way of error handling
- should really be using applyPatches() but im not
- the api is a little funny
How to use:
$ yarn
$ yarn build
Then run
$ node client.js $DOCID
In two or three different windows and watch each client editing the same document.