@storehouse/redis - v0.1.0
    Preparing search index...

    Class RedisManager<M, F, S, RESP, TYPE_MAPPING>

    Runs operations through an operation guard, which can enforce policies such as retries, circuit breaking, or fail-fast behavior.

    Type Parameters

    • M extends RedisModules = RedisDefaultModules
    • F extends RedisFunctions = RedisFunctions
    • S extends RedisScripts = RedisScripts
    • RESP extends RespVersions = 3
    • TYPE_MAPPING extends TypeMapping = TypeMapping

    Implements

    Index
    • Creates a new RedisManager instance.

      Type Parameters

      • M extends RedisModules = RedisDefaultModules
      • F extends RedisFunctions = RedisFunctions
      • S extends RedisScripts = RedisScripts
      • RESP extends RespVersions = 3
      • TYPE_MAPPING extends TypeMapping = TypeMapping

      Parameters

      Returns RedisManager<M, F, S, RESP, TYPE_MAPPING>

      The connection is created but not opened. You must call connect() to establish the connection. Connection events (error, connect, ready, end, reconnecting) are automatically registered and logged.

    logger: Debugger
    name: string

    The name of this manager instance.

    type: "@storehouse/redis" = '@storehouse/redis'

    Identifier for the manager type.

    • Closes the Redis connection gracefully using the QUIT command.

      Returns Promise<string>

      A promise that resolves to the Redis server's response to the QUIT command

      await manager.close();
      
    • Alias for close(). Closes the Redis connection gracefully.

      Returns Promise<string>

      A promise that resolves to the Redis server's response to the QUIT command

      await manager.closeConnection();
      
    • Creates a repository for the given schema, allowing interaction with the corresponding Redis data.

      Type Parameters

      • TSchema extends StandardSchemaV1<unknown, unknown>

      Parameters

      • schema: Schema<TSchema>

        The schema for which to create the repository

      Returns Repository<TSchema>

      A repository instance for the specified schema

    • Gets the underlying Redis client connection.

      Returns RedisClientType<M, F, S, RESP, TYPE_MAPPING>

      The Redis client instance

      const client = manager.getConnection();
      await client.set('mykey', 'myvalue');
    • Get a model by name (optional)

      Parameters

      • _name: string

      Returns unknown

      The model instance or undefined if not found

    • Performs a comprehensive health check on the Redis connection. Tests connectivity by sending a PING command and gathering connection metrics.

      Returns Promise<RedisClientHealthCheckResult>

      A promise that resolves to a detailed health check result including:

      • Connection status (open/ready)
      • Ping response
      • Registered models
      • Response latency
      • Error details (if unhealthy)
      const health = await manager.healthCheck();
      if (health.healthy) {
      console.log(`Redis is healthy. Latency: ${health.details.latency}`);
      console.log(`Models: ${health.details.models?.join(', ')}`);
      } else {
      console.error(`Redis is unhealthy: ${health.message}`);
      }
    • Checks if the Redis connection is currently open.

      Returns Promise<boolean>

      A promise that resolves to true if connected, false otherwise

      if (await manager.isConnected()) {
      console.log('Redis is connected');
      }
    • Executes an asynchronous operation with the Redis connection, ensuring that the connection is ready and open, and enforcing a command timeout.

      Because node-redis' own command timeout stops once the command is written to the socket, so it does not protect against a frozen Redis.

      This method adds an additional layer of protection by enforcing a command timeout at the application level.

      The value of the command timeout is taken from the options provided during the client's initialization (commandOptions.timeout) or defaults to 5000 milliseconds if not specified.

      Type Parameters

      • R

      Parameters

      • operation: () => Promise<R>

        The asynchronous operation to execute with the Redis connection

      Returns Promise<R>

      A promise that resolves to the result of the operation or rejects with an error if the operation fails or times out

      If the Redis connection is not ready or not open

      If the operation exceeds the configured command timeout