isReadonlyReplicaError (cache/recovery.ts)

librechat · packages/api/src/cache/recovery.ts · typescript · MIT
database

Creates a handler that recovers from Redis READONLY errors by reconnecting the client with backoff, improving reliability.

// Source: https://github.com/danny-avila/librechat | License: MIT | Copyright 2026 LibreChat
// Provided via justclaw.it.com; keep this notice with the code.
import { logger } from '@librechat/data-schemas';

/** Reply prefix Redis returns for writes sent to a demoted replica. */
export const READONLY_ERROR_PREFIX = 'READONLY';

export type ReconnectableClient = {
  readonly isOpen: boolean;
  readonly isReady: boolean;
  destroy(): void;
  connect(): Promise<unknown>;
};

export type ReadonlyRecoveryOptions = {
  client: ReconnectableClient;
  /**
   * Minimum spacing between reconnect attempts. A failover produces READONLY
   * replies by the hundred per second, and a reconnect issued before the
   * topology settles can land on the demoted node again, so attempts are
   * spaced out an

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key