Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add example to README #12

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
docs: add example to README
  • Loading branch information
wang1xiang authored Jan 30, 2024
commit c9f88fa127fcb1ed218a0b2d2e3b85e8a18eeb89
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,3 +2,28 @@
> Redis persistence layer for [Yjs](https://github.com/yjs/yjs)

![work in progress](https://cdn.pixabay.com/photo/2014/11/04/13/20/lego-516557_960_720.jpg)

## Example

```js
const { RedisPersistence } = require('y-redis')

// redis configuration information
const redisConfig = {
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
password: process.env.REDIS_PASSWORD,
db: process.env.REDIS_DB,
keyPrefix: process.env.REDIS_KEY_PREFIIX,
}

const rp = new RedisPersistence({ redisOpts: redisConfig })
const persistence = {
provider: rp,
bindState: async (docName, ydoc) => {
rp.closeDoc(docName)
return rp.bindState(docName, ydoc)
},
writeState: async (docName, ydoc) => {},
}
```