lib/util.js
function createRedisClient(clientConfig, callback) {
  let c = require('config');
  let client = null;
  let conId = null;

  let redisOpts = {
    //showFriendlyErrorStack: true,
    db: clientConfig.dbIndex,
    password: clientConfig.password,
    connectionName: clientConfig.connectionName || c.get('redis.connectionName'),
    retryStrategy: function (times) {
      return times > 10 ? 3000 : 1000;
    }
  };

  // add tls support (simple and complex)
  // 1) boolean flag - simple tls without cert validation and similiar
  // 2) object - all params allowed for tls socket possible (see https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
  if (typeof clientConfig.tls === 'boolean' && clientConfig.tls) {
    redisOpts.tls = {};
  }
  else if (typeof clientConfig.tls === 'object') {
    redisOpts.tls = clientConfig.tls;
  }

  if (clientConfig.sentinels) {
    Object.assign(redisOpts, {
      sentinels: clientConfig.sentinels,
      name: clientConfig.sentinel_name || 'mymaster',
    });
    conId = `S:${redisOpts.sentinels[0].host}:${redisOpts.sentinels[0].port}:${redisOpts.name}-${redisOpts.db}`;
  }
  else {
    Object.assign(redisOpts, {
      port: clientConfig.port,
      host: clientConfig.host,
      path: clientConfig.path,
      family: 4
    });
    if (clientConfig.path) {
      // unix-socket:
      // no need for strong crypto here, just short string hopefully unique between different socket paths
      // only needed if someone uses this app with multiple different local redis sockets...
      // ATTN: use no hardcoded algorithm as some systems may not support it. just search for a sha-something
      let hashAlg = crypto.getHashes().find((h) => (h.startsWith('sha')));
      let cid =crypto.createHash(hashAlg).update(clientConfig.path).digest('hex').substring(24);
      conId = `U:${cid}:${redisOpts.db}`;
    }
    else {
      conId = `R:${redisOpts.host}:${redisOpts.port}:${redisOpts.db}`;
    }
  }
  client = new Redis(redisOpts);
  client.label = clientConfig.label;
  client.options.connectionId = clientConfig.connectionId = conId;
  return client;
}
function createRedisClient(clientConfig, callback) {
  let c = require('config');
  let client = null;
  let conId = null;

  let redisOpts = {
    //showFriendlyErrorStack: true,
    db: clientConfig.dbIndex,
    password: clientConfig.password,
    connectionName: clientConfig.connectionName || c.get('redis.connectionName'),
    retryStrategy: function (times) {
      return times > 10 ? 3000 : 1000;
    }
  };

  // add tls support (simple and complex)
  // 1) boolean flag - simple tls without cert validation and similiar
  // 2) object - all params allowed for tls socket possible (see https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
  if (typeof clientConfig.tls === 'boolean' && clientConfig.tls) {
    redisOpts.tls = {};
  }
  else if (typeof clientConfig.tls === 'object') {
    redisOpts.tls = clientConfig.tls;
  }

  if (clientConfig.sentinels) {
    Object.assign(redisOpts, {
      sentinels: clientConfig.sentinels,
      name: clientConfig.sentinel_name || 'mymaster',
    });
    conId = `S:${redisOpts.sentinels[0].host}:${redisOpts.sentinels[0].port}:${redisOpts.name}-${redisOpts.db}`;
  }
  else {
    Object.assign(redisOpts, {
      port: clientConfig.port,
      host: clientConfig.host,
      path: clientConfig.path,
      family: 4
    });
    if (clientConfig.path) {
      // unix-socket:
      // no need for strong crypto here, just short string hopefully unique between different socket paths
      // only needed if someone uses this app with multiple different local redis sockets...
      // ATTN: use no hardcoded algorithm as some systems may not support it. just search for a sha-something
      let hashAlg = crypto.getHashes().find((h) => (h.startsWith('sha')));
      let cid =crypto.createHash(hashAlg).update(clientConfig.path).digest('hex').substring(24);
      conId = `U:${cid}:${redisOpts.db}`;
    }
    else {
      conId = `R:${redisOpts.host}:${redisOpts.port}:${redisOpts.db}`;
    }
  }
  client = new Redis(redisOpts);
  client.label = clientConfig.label;
  client.options.connectionId = clientConfig.connectionId = conId;
  return client;
}
function createRedisClient ( clientConfig , callback ) { let c = require ( 'config' ) ; let client = null ; let conId = null ; let redisOpts = { //showFriendlyErrorStack: true, db : clientConfig . dbIndex , password : clientConfig . password , connectionName : clientConfig . connectionName || c . get ( 'redis.connectionName' ) , retryStrategy : function ( times ) { return times > 10 ? 3000 : 1000 ; } } ; // add tls support (simple and complex) // 1) boolean flag - simple tls without cert validation and similiar // 2) object - all params allowed for tls socket possible (see https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) if ( typeof clientConfig . tls === 'boolean' && clientConfig . tls ) { redisOpts . tls = { } ; } else if ( typeof clientConfig . tls === 'object' ) { redisOpts . tls = clientConfig . tls ; } if ( clientConfig . sentinels ) { Object . assign ( redisOpts , { sentinels : clientConfig . sentinels , name : clientConfig . sentinel_name || 'mymaster' , } ) ; conId = ` ${ redisOpts . sentinels [ 0 ] . host } ${ redisOpts . sentinels [ 0 ] . port } ${ redisOpts . name } ${ redisOpts . db } ` ; } else { Object . assign ( redisOpts , { port : clientConfig . port , host : clientConfig . host , path : clientConfig . path , family : 4 } ) ; if ( clientConfig . path ) { // unix-socket: // no need for strong crypto here, just short string hopefully unique between different socket paths // only needed if someone uses this app with multiple different local redis sockets... // ATTN: use no hardcoded algorithm as some systems may not support it. just search for a sha-something let hashAlg = crypto . getHashes ( ) . find ( ( h ) => ( h . startsWith ( 'sha' ) ) ) ; let cid = crypto . createHash ( hashAlg ) . update ( clientConfig . path ) . digest ( 'hex' ) . substring ( 24 ) ; conId = ` ${ cid } ${ redisOpts . db } ` ; } else { conId = ` ${ redisOpts . host } ${ redisOpts . port } ${ redisOpts . db } ` ; } } client = new Redis ( redisOpts ) ; client . label = clientConfig . label ; client . options . connectionId = clientConfig . connectionId = conId ; return client ; }
Function to craete a new redis client object by given parameter
This one is used by creating clients at startup from command line, config file
or new connections added via ui during runtime.
The redis client created can be either a normal redis client or a sentinel client, base on
configuration given.

@param {object} clientConfig - configuration to create client from
@param {function} callback - function with error object and new client created: cb(error, client)
Function to craete a new redis client object by given parameter This one is used by creating clients at startup from command line config file or new connections added via ui during runtime . The redis client created can be either a normal redis client or a sentinel client base on configuration given .