@socket.io/redis-streams-adapter
Version:
The Socket.IO adapter based on Redis Streams, allowing to broadcast events between several Socket.IO servers
58 lines (57 loc) • 2.15 kB
TypeScript
import { ClusterAdapterWithHeartbeat } from "socket.io-adapter";
import type { ClusterAdapterOptions, ClusterMessage, PrivateSessionId, Session, ServerId, ClusterResponse } from "socket.io-adapter";
export interface RedisStreamsAdapterOptions {
/**
* The name of the Redis stream.
* @default "socket.io"
*/
streamName?: string;
/**
* The maximum size of the stream. Almost exact trimming (~) is used.
* @default 10_000
*/
maxLen?: number;
/**
* The number of elements to fetch per XREAD call.
* @default 100
*/
readCount?: number;
/**
* The prefix of the key used to store the Socket.IO session, when the connection state recovery feature is enabled.
* @default "sio:session:"
*/
sessionKeyPrefix?: string;
}
interface RawClusterMessage {
uid: string;
nsp: string;
type: string;
data?: string;
}
/**
* Returns a function that will create a new adapter instance.
*
* @param redisClient - a Redis client that will be used to publish messages
* @param opts - additional options
*/
export declare function createAdapter(redisClient: any, opts?: RedisStreamsAdapterOptions & ClusterAdapterOptions): (nsp: any) => RedisStreamsAdapter;
declare class RedisStreamsAdapter extends ClusterAdapterWithHeartbeat {
#private;
constructor(nsp: any, redisClient: any, opts: Required<RedisStreamsAdapterOptions> & ClusterAdapterOptions);
doPublish(message: ClusterMessage): any;
protected doPublishResponse(requesterUid: ServerId, response: ClusterResponse): Promise<void>;
static encode(message: ClusterMessage): RawClusterMessage;
onRawMessage(rawMessage: RawClusterMessage, offset: string): any;
static decode(rawMessage: RawClusterMessage): ClusterMessage;
persistSession(session: any): void;
restoreSession(pid: PrivateSessionId, offset: string): Promise<Session>;
/**
* Exclusive ranges were added in Redis 6.2, so this is necessary for previous versions.
*
* @see https://redis.io/commands/xrange/
*
* @param offset
*/
static nextOffset(offset: any): string;
}
export {};