All files / redis-smq-monitor-app/src/common/redis-keys redis-keys.ts

100% Statements 32/32
100% Branches 2/2
100% Functions 5/5
100% Lines 32/32

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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88      57x     57x     57x   57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x               1698x 1698x 10488x       1698x     57x   1100x                     1100x     200x 200x       200x           398x 398x                   398x            
// Key segments separator
import { TQueueParams } from 'redis-smq/dist/types';
 
const keySegmentSeparator = ':';
 
// Key prefix
const nsPrefix = 'redis-smq-monitor-server-v700-rc0';
 
// Namespaces
const globalNamespace = 'global';
 
enum ERedisKey {
  KEY_LOCK_MONITOR_SERVER_WORKERS,
  KEY_RATE_CONSUMER_ACKNOWLEDGED,
  KEY_RATE_QUEUE_ACKNOWLEDGED,
  KEY_RATE_QUEUE_ACKNOWLEDGED_INDEX,
  KEY_RATE_QUEUE_DEAD_LETTERED,
  KEY_RATE_QUEUE_DEAD_LETTERED_INDEX,
  KEY_RATE_QUEUE_PUBLISHED,
  KEY_RATE_QUEUE_PUBLISHED_INDEX,
  KEY_RATE_GLOBAL_ACKNOWLEDGED,
  KEY_RATE_GLOBAL_ACKNOWLEDGED_INDEX,
  KEY_RATE_GLOBAL_DEAD_LETTERED,
  KEY_RATE_GLOBAL_DEAD_LETTERED_INDEX,
  KEY_RATE_GLOBAL_PUBLISHED,
  KEY_RATE_GLOBAL_PUBLISHED_INDEX,
  KEY_RATE_CONSUMER_DEAD_LETTERED,
}
 
function makeNamespacedKeys<T extends Record<string, ERedisKey>>(
  keys: T,
  namespace: string,
  ...rest: string[]
): Record<Extract<keyof T, string>, string> {
  const result: Record<string, string> = {};
  for (const k in keys) {
    result[k] = [nsPrefix, namespace, keys[k], ...rest].join(
      keySegmentSeparator,
    );
  }
  return result;
}
 
export const redisKeys = {
  getMainKeys() {
    const mainKeys = {
      keyLockMonitorServerWorkers: ERedisKey.KEY_LOCK_MONITOR_SERVER_WORKERS,
      keyRateGlobalDeadLettered: ERedisKey.KEY_RATE_GLOBAL_DEAD_LETTERED,
      keyRateGlobalAcknowledged: ERedisKey.KEY_RATE_GLOBAL_ACKNOWLEDGED,
      keyRateGlobalPublished: ERedisKey.KEY_RATE_GLOBAL_PUBLISHED,
      keyRateGlobalDeadLetteredIndex:
        ERedisKey.KEY_RATE_GLOBAL_DEAD_LETTERED_INDEX,
      keyRateGlobalAcknowledgedIndex:
        ERedisKey.KEY_RATE_GLOBAL_ACKNOWLEDGED_INDEX,
      keyRateGlobalInputIndex: ERedisKey.KEY_RATE_GLOBAL_PUBLISHED_INDEX,
    };
    return makeNamespacedKeys(mainKeys, globalNamespace);
  },
  getConsumerKeys(instanceId: string) {
    const mainKeys = this.getMainKeys();
    const consumerKeys = {
      keyRateConsumerDeadLettered: ERedisKey.KEY_RATE_CONSUMER_DEAD_LETTERED,
      keyRateConsumerAcknowledged: ERedisKey.KEY_RATE_CONSUMER_ACKNOWLEDGED,
    };
    return {
      ...mainKeys,
      ...makeNamespacedKeys(consumerKeys, globalNamespace, instanceId),
    };
  },
  getQueueKeys(queueParams: TQueueParams) {
    const mainKeys = this.getMainKeys();
    const queueKeys = {
      keyRateQueueDeadLettered: ERedisKey.KEY_RATE_QUEUE_DEAD_LETTERED,
      keyRateQueueAcknowledged: ERedisKey.KEY_RATE_QUEUE_ACKNOWLEDGED,
      keyRateQueuePublished: ERedisKey.KEY_RATE_QUEUE_PUBLISHED,
      keyRateQueueDeadLetteredIndex:
        ERedisKey.KEY_RATE_QUEUE_DEAD_LETTERED_INDEX,
      keyRateQueueAcknowledgedIndex:
        ERedisKey.KEY_RATE_QUEUE_ACKNOWLEDGED_INDEX,
      keyRateQueuePublishedIndex: ERedisKey.KEY_RATE_QUEUE_PUBLISHED_INDEX,
    };
    return {
      ...mainKeys,
      ...makeNamespacedKeys(queueKeys, queueParams.ns, queueParams.name),
    };
  },
};