From c9f88fa127fcb1ed218a0b2d2e3b85e8a18eeb89 Mon Sep 17 00:00:00 2001 From: wangxiang <756638369@qq.com> Date: Tue, 30 Jan 2024 11:09:25 +0800 Subject: [PATCH] docs: add example to README --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 76592e8..625a963 100644 --- a/README.md +++ b/README.md @@ -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) => {}, +} +```