All files / redis-smq-monitor-app/tests/common redis-clients.ts

100% Statements 15/15
80% Branches 4/5
100% Functions 2/2
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2757x 57x 57x 57x   57x   57x 97x 97x         97x 97x     57x 57x 97x 97x 97x        
import { RedisClient } from 'redis-smq-common';
import { promisifyAll } from 'bluebird';
import { config } from './config';
import { RedisClientName } from 'redis-smq-common/dist/types';
 
const redisClients: RedisClient[] = [];
 
export async function getRedisInstance() {
  const RedisClientAsync = promisifyAll(RedisClient);
  const c = promisifyAll(
    await RedisClientAsync.getNewInstanceAsync(
      config.redis ?? { client: RedisClientName.REDIS },
    ),
  );
  redisClients.push(c);
  return c;
}
 
export async function shutdownRedisClients() {
  while (redisClients.length) {
    const redisClient = redisClients.pop();
    if (redisClient) {
      await promisifyAll(redisClient).haltAsync();
    }
  }
}