Fake Mirrors
    Preparing search index...

    Class RedisDatabaseConnector

    Redis-based database connector implementation.

    Uses the official node-redis client with custom Redis Functions.

    https://github.com/redis/node-redis - Node Redis client

    Depends:

    import { DIContainer } from '@famir/common'
    import { RedisDatabaseConnector } from '@famir/database'

    // Get container singleton
    const container = DIContainer.getInstance()

    // Register dependency in container
    RedisDatabaseConnector.register(container)
    import { DIContainer } from '@famir/common'
    import { DATABASE_CONNECTOR, DatabaseConnector } from '@famir/domain'
    import { RedisDatabaseConnection } from '@famir/database'

    // Get container singleton
    const container = DIContainer.getInstance()

    // Resolve dependency from container
    const connector = container.resolve<DatabaseConnector>(DATABASE_CONNECTOR)

    // Connect to Redis
    await connector.connect()

    // Get underlying Redis connection
    const connection = connector.getConnection<RedisDatabaseConnection>()

    // Execute ping command
    const result = await connection.PING()
    console.log(result) // 'PONG'

    // Close connection
    await connector.close()

    Implements

    • Gracefully closes a connection to the database.

      This method should be called during application shutdown to ensure all pending operations are completed and resources are released.

      Returns Promise<void>

      LifecycleError If the connection cannot be closed properly.

    • Establishes a connection to the database.

      This method should be called during application bootstrap to ensure the connection is ready before any operations are performed.

      Returns Promise<void>

      LifecycleError If the database connection cannot be established.

    • Retrieves the underlying database connection.

      This method uses a type assertion to return the connection as the requested type. It is the caller's responsibility to ensure the correct type is used.

      Type Parameters

      • T

        The expected type of the database connection.

      Returns T

      The database connection cast to type T.

    • Registers the connector as a singleton in the DI container.

      Parameters

      • container: DIContainer

        The DI container to register in.

      Returns void