Class IORedisConnector

Description

IORedis connector

Features:

  • connector manager for redis

Example

import { inject, container, Types, Core } from '@biorate/inversion';
import { IConfig, Config } from '@biorate/config';
import { IORedisConnector, IORedisConfig } from '@biorate/ioredis';

class Root extends Core() {
@inject(IORedisConnector) public connector: IORedisConnector;
}

container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
container.bind<IORedisConnector>(IORedisConnector).toSelf().inSingletonScope();
container.bind<Root>(Root).toSelf().inSingletonScope();

container.get<IConfig>(Types.Config).merge({
IORedis: [
{
name: 'connection',
options: {
host: 'localhost',
port: 6379,
},
},
],
});

(async () => {
const root = container.get<Root>(Root);
await root.$run();

await root.connector.current!.set('key', 'value');
console.log(await root.connector.current!.get('key')); // value
})();

Hierarchy

Constructors

Properties

#connections: Map<string, Redis>

Description

Private connections storage

#connections: Map<string, Redis> = ...

Description

Private connections storage

#current: Redis

Description

Private link to selected (used) connection

#current: Redis = undefined

Description

Private link to selected (used) connection

config: IConfig

Description

Config dependency

namespace: "IORedis" = 'IORedis'

Description

Namespace path for fetching configuration

Accessors

  • get connections(): Map<string, T>
  • Returns Map<string, T>

    Description

    Connections storage

  • get current(): T
  • Returns T

    Description

    Link to selected (used) connection

Methods

  • Parameters

    • Optional name: string
      Optional

    Returns Redis

    Description

    Method for get existed the connection

  • Parameters

    Returns Promise<Redis>

    Description

    Method for creating new connection

  • Parameters

    • Optional name: string
      Optional

    Returns Redis

    Description

    Alias for connection method

  • Returns Promise<void>

    Description

    Initialize method

  • Parameters

    • name: string

    Returns void

    Description

    Method for changing current connection

Generated using TypeDoc