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

cameri / nostream / 25529283840

08 May 2026 12:17AM UTC coverage: 64.439% (-0.5%) from 64.937%
25529283840

Pull #615

github

web-flow
Merge fb553e964 into 6c8e29a01
Pull Request #615: test: add unit tests for remaining app workers (#489)

1801 of 3166 branches covered (56.89%)

Branch coverage included in aggregate %.

4148 of 6066 relevant lines covered (68.38%)

8.66 hits per line

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

46.43
/src/cache/client.ts
1
import { createClient, RedisClientOptions } from 'redis'
1✔
2
import { CacheClient } from '../@types/cache'
3
import { createLogger } from '../factories/logger-factory'
1✔
4

5
const logger = createLogger('cache-client')
1✔
6

7
const redactRedisUrlCredentials = (url: string): string => {
1✔
8
  try {
×
9
    const parsedUrl = new URL(url)
×
10

11
    if (!parsedUrl.username && !parsedUrl.password) {
×
12
      return url
×
13
    }
14

15
    parsedUrl.username = parsedUrl.username ? '***' : ''
×
16
    parsedUrl.password = parsedUrl.password ? '***' : ''
×
17

18
    return parsedUrl.toString()
×
19
  } catch {
20
    return url
×
21
  }
22
}
23

24
export const getCacheConfig = (): RedisClientOptions => {
1✔
25
  const password = process.env.REDIS_PASSWORD
4✔
26

27
  if (process.env.REDIS_URI) {
4✔
28
    return {
1✔
29
      url: process.env.REDIS_URI,
30
      ...(password ? { password } : {}),
1!
31
    }
32
  }
33

34
  const host = process.env.REDIS_HOST
3✔
35
  const port = process.env.REDIS_PORT
3✔
36

37
  if (password) {
3✔
38
    const username = process.env.REDIS_USER ?? 'default'
2✔
39

40
    return {
2✔
41
      url: `redis://${host}:${port}`,
42
      username,
43
      password,
44
    }
45
  }
46

47
  return {
1✔
48
    url: `redis://${host}:${port}`,
49
  }
50
}
51

52
let instance: CacheClient | undefined = undefined
1✔
53

54
export const getCacheClient = (): CacheClient => {
1✔
55
  if (!instance) {
×
56
    const config = getCacheConfig()
×
57
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
58
    const { password: _, ...loggableConfig } = config
×
59
    logger('config: %o', {
×
60
      ...loggableConfig,
61
      ...(loggableConfig.url ? { url: redactRedisUrlCredentials(loggableConfig.url) } : {}),
×
62
    })
63
    instance = createClient(config)
×
64
  }
65

66
  return instance
×
67
}
68

69
export const closeCacheClient = async (): Promise<void> => {
1✔
70
  if (instance?.isOpen) {
10!
71
    await instance.disconnect()
×
72
    instance = undefined
×
73
  }
74
}
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

© 2026 Coveralls, Inc