1.7.0 • Published 4 months ago

@xnestjs/ioredis v1.7.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

@xnestjs/ioredis

NestJS extension library for ioredis

Install

npm install @xnestjs/ioredis
# or using yarn
yarn add @xnestjs/ioredis

Usage

Register standalone sync

An example of nestjs module that creates RedisClient with standalone connection.

// module.ts
import { Module } from '@nestjs/common';
import { RedisModule } from '@xnestjs/ioredis';

@Module({
    imports: [
        RedisModule.forRoot({
            useValue: {
                host: 'localhost',
                port: 6379
            }
        }),
    ]
})
export class MyModule {
}

Register cluster sync

An example of nestjs module that creates RedisClient with cluster connection.

// module.ts
import { Module } from '@nestjs/common';
import { RedisModule } from '@xnestjs/ioredis';

@Module({
    imports: [
        RedisModule.forRoot({
            useValue: {
                nodes: ['localhost'],
            }
        }),
    ]
})
export class MyModule {
}

Register standalone async

An example of nestjs module that creates RedisClient with standalone connection async

// module.ts
import { Module } from '@nestjs/common';
import { RedisModule } from '@xnestjs/ioredis';

@Module({
    imports: [
        ElasticsearchModule.forRootAsync({
            inject: [ConfigModule],
            useFactory: (config: ConfigService) => ({
                host: config.get('REDIS_HOST'),
            }),
        }),
    ]
})
export class MyModule {
}

Register cluster async

An example of nestjs module that creates RedisClient with cluster connection async

// module.ts
import { Module } from '@nestjs/common';
import { RedisModule } from '@xnestjs/ioredis';

@Module({
    imports: [
        ElasticsearchModule.forRootAsync({
            inject: [ConfigModule],
            useFactory: (config: ConfigService) => ({
                nodes: config.get('REDIS_NODES'),
            }),
        }),
    ]
})
export class MyModule {
}

Environment Variables

The library supports configuration through environment variables. Environment variables below is accepted. All environment variables starts with prefix (REDIS_). This can be configured while registering the module.

<--- BEGIN env --->

Standalone Connection Variables

The following environment variables apply to the standalone connection.

Environment VariableTypeDefaultDescription
REDIS_HOSTStringlocalhost
REDIS_PORTNumber6379

Cluster Connection Variables

The following environment variables apply to the standalone connection.

Environment VariableTypeDefaultDescription
NODESString!localhost

Common Variables

Environment VariableTypeDefaultDescription
REDIS_DBNumber0Hostname for Redis Server
REDIS_USERNAMEStringPort number
REDIS_PASSWORDStringIf set, client will send AUTH command with the value of this option as the first argument when connected.
REDIS_CONNECTION_NAMEStringIf set, client will send AUTH command with the value of this option when connected.
REDIS_AUTO_RESUBSCRIBEBooleanWhen the client reconnects, channels subscribed in the previous connection will be resubscribed automatically if value is true.
REDIS_RECONNECT_ON_ERRORNumberOne of 0, 1, 2
REDIS_CONNECT_TIMEOUTNumber10000How long the client will wait before killing a socket due to inactivity during initial connection.
REDIS_SOCKET_TIMEOUTNumberDefines the socket timeout value
REDIS_KEEP_ALIVEBooleanEnable/disable keep-alive functionality.
REDIS_NO_DELAYBooleanEnable/disable the use of Nagle's algorithm.
REDIS_MAX_RETRIES_PER_REQUESTNumberDefines max retries per request value

<--- END env --->

1.7.0

4 months ago

1.6.4

4 months ago

1.6.3

4 months ago

1.6.2

4 months ago

1.5.3

4 months ago

1.6.1

4 months ago

1.5.2

4 months ago

1.6.0

4 months ago

1.2.6

4 months ago

1.2.5

4 months ago

1.5.1

4 months ago

1.5.0

4 months ago

1.3.1

4 months ago

1.2.0

6 months ago

1.2.3

6 months ago

1.2.2

6 months ago

1.2.1

6 months ago

1.1.0

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

0.10.4

8 months ago

0.10.0

10 months ago

0.9.0

11 months ago

0.8.2

11 months ago

0.8.1

12 months ago

0.8.0

12 months ago

0.7.1

2 years ago

0.7.0

2 years ago

0.1.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.4.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.0.1

3 years ago