• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-client-gateway / 12600568711

03 Jan 2025 04:15PM UTC coverage: 90.127% (-0.04%) from 90.168%
12600568711

Pull #2222

github

PooyaRaki
fix review comments
Pull Request #2222: Add Authentication to Redis

2836 of 3525 branches covered (80.45%)

Branch coverage included in aggregate %.

9 of 10 new or added lines in 2 files covered. (90.0%)

9643 of 10321 relevant lines covered (93.43%)

467.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.96
/src/datasources/cache/cache.module.ts
1
import { Global, Module } from '@nestjs/common';
118✔
2
import { createClient } from 'redis';
118✔
3
import { IConfigurationService } from '@/config/configuration.service.interface';
118✔
4
import { CacheService } from '@/datasources/cache/cache.service.interface';
118✔
5
import { RedisCacheService } from '@/datasources/cache/redis.cache.service';
118✔
6
import { CacheReadiness } from '@/domain/interfaces/cache-readiness.interface';
118✔
7
import { ILoggingService, LoggingService } from '@/logging/logging.interface';
118✔
8
import { CacheKeyPrefix } from '@/datasources/cache/constants';
118✔
9

10
export type RedisClientType = ReturnType<typeof createClient>;
11

12
async function redisClientFactory(
13
  configurationService: IConfigurationService,
14
  loggingService: ILoggingService,
15
): Promise<RedisClientType> {
16
  const redisUser = configurationService.get<string>('redis.user');
20✔
17
  const redisPass = configurationService.get<string>('redis.pass');
20✔
18
  const redisHost = configurationService.getOrThrow<string>('redis.host');
20✔
19
  const redisPort = configurationService.getOrThrow<string>('redis.port');
20✔
20
  const authString = redisUser && redisPass ? `${redisUser}:${redisPass}@` : '';
20!
21
  const client: RedisClientType = createClient({
20✔
22
    url: `redis://${authString}${redisHost}:${redisPort}`,
23
  });
24
  client.on('error', (err) =>
20✔
NEW
25
    loggingService.error(`Redis client error: ${err}`),
×
26
  );
27
  await client.connect();
20✔
28
  return client;
20✔
29
}
30

31
@Global()
32
@Module({
33
  providers: [
34
    {
35
      provide: 'RedisClient',
36
      useFactory: redisClientFactory,
37
      inject: [IConfigurationService, LoggingService],
38
    },
39
    { provide: CacheService, useClass: RedisCacheService },
40
    { provide: CacheReadiness, useExisting: CacheService },
41
    { provide: CacheKeyPrefix, useValue: '' },
42
  ],
43
  exports: [CacheService, CacheReadiness],
44
})
45
export class CacheModule {}
118✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc