53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { Logger, Module } from '@nestjs/common';
|
|
import { createClient } from 'redis';
|
|
import { SecretModule } from '../../global/secret/secret.module';
|
|
import { SecretService } from '../../global/secret/secret.service';
|
|
import { loadRedisClientOptions } from '../../global/redis/redis.config';
|
|
import { AUCTION_REDIS_CLIENT } from './auction-redis.constants';
|
|
import {
|
|
AuctionRedisService,
|
|
type AuctionRedisClient,
|
|
} from './auction-redis.service';
|
|
import { AuctionRedisCommandService } from './auction-redis-command.service';
|
|
import { AuctionRedisStateReaderService } from './auction-redis-state-reader.service';
|
|
|
|
@Module({
|
|
imports: [SecretModule],
|
|
providers: [
|
|
{
|
|
provide: AUCTION_REDIS_CLIENT,
|
|
inject: [SecretService],
|
|
useFactory: async (
|
|
secretService: SecretService,
|
|
): Promise<AuctionRedisClient> => {
|
|
const logger = new Logger('AuctionRedisClient');
|
|
const client = createClient(
|
|
await loadRedisClientOptions(secretService),
|
|
);
|
|
client.on('error', (error: unknown) => {
|
|
logger.error(
|
|
`Auction Redis client error: ${
|
|
error instanceof Error ? error.message : String(error)
|
|
}`,
|
|
);
|
|
});
|
|
|
|
await client.connect();
|
|
logger.log('Auction Redis connected');
|
|
|
|
return client;
|
|
},
|
|
},
|
|
AuctionRedisService,
|
|
AuctionRedisCommandService,
|
|
AuctionRedisStateReaderService,
|
|
],
|
|
exports: [
|
|
AuctionRedisService,
|
|
AuctionRedisCommandService,
|
|
AuctionRedisStateReaderService,
|
|
AUCTION_REDIS_CLIENT,
|
|
],
|
|
})
|
|
export class AuctionRedisModule {}
|