import RedisClient from 'ioredis'; import Redlock from 'redlock'; import { Document, Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload } from '@hocuspocus/server'; export interface Configuration { /** * Redis port */ port: number; /** * Redis host */ host: string; /** * Options passed directly to Redis constructor * * https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options */ options?: RedisClient.RedisOptions; /** * An unique instance name, required to filter messages in Redis. * If none is provided an unique id is generated. */ identifier: string; /** * Namespace for Redis keys, if none is provided 'hocuspocus' is used */ prefix: string; /** * The maximum time for the Redis lock in ms (in case it can’t be released). */ lockTimeout: number; } export declare class Redis implements Extension { /** * Make sure to give that extension a higher priority, so * the `onStoreDocument` hook is able to intercept the chain, * before documents are stored to the database. */ priority: number; configuration: Configuration; pub: RedisClient.Redis; sub: RedisClient.Redis; documents: Map; redlock: Redlock; locks: Map; constructor(configuration: Partial); private getKey; private pubKey; private subKey; private lockKey; /** * Once a document is laoded, subscribe to the channel in Redis. */ afterLoadDocument({ documentName, document }: afterLoadDocumentPayload): Promise; /** * Publish the first sync step through Redis. */ private publishFirstSyncStep; /** * Let’s ask Redis who is connected already. */ private requestAwarenessFromOtherInstances; /** * Before the document is stored, make sure to set a lock in Redis. * That’s meant to avoid conflicts with other instances trying to store the document. */ onStoreDocument({ documentName }: onStoreDocumentPayload): Promise; /** * Release the Redis lock, so other instances can store documents. */ afterStoreDocument({ documentName }: afterStoreDocumentPayload): Promise; /** * Handle awareness update messages received directly by this Hocuspocus instance. */ onAwarenessUpdate({ documentName, awareness }: onAwarenessUpdatePayload): Promise; /** * Handle incoming messages published on all subscribed document channels. * Note that this will also include messages from ourselves as it is not possible * in Redis to filter these. */ private handleIncomingMessage; /** * Make sure to *not* listen for further changes, when there’s * noone connected anymore. */ onDisconnect: ({ documentName, clientsCount }: onDisconnectPayload) => Promise; /** * Kill the Redlock connection immediately. */ onDestroy(): Promise; }