lib/util.js
function parseRedisSentinel(key, sentinelsString) {
  if (!sentinelsString) return [];

  // convert array entries from string to object if needed
  if (Array.isArray(sentinelsString)) {
    sentinelsString.forEach(function(entry, index) {
      if (typeof entry === 'string') {
        let tmp = entry.trim().split(':');
        sentinelsString[index] = {host: tmp[0].toLowerCase(), port: parseInt(tmp[1])};
      }
    });
    return sentinelsString.sort((i1, i2) => ((i1.host.toLowerCase()) > i2.host.toLowerCase() || i1.port - i2.port));
  }

  if (typeof sentinelsString !== 'string') {
    throw new Error('Invalid type for key ' + key + ': must be either comma separated string with sentinels or list of them');
  }

  try {
    let sentinels = [];
    if (sentinelsString.startsWith('[')) {
      let obj = JSON.parse(sentinelsString);
      obj.forEach(function(sentinel) {
        if (typeof sentinel === 'object') sentinels.push(sentinel);
        else {
          let tmp = sentinel.trim().split(':');
          sentinels.push({host: tmp[0].toLowerCase(), port: parseInt(tmp[1])});
        }
      });
    }
    else {
      // simple string, comma separated list of host:port
      let obj = sentinelsString.split(',');
      obj.forEach(function(sentinel) {
        if (sentinel && sentinel.trim()) {
          let tmp = sentinel.trim().split(':');
          sentinels.push({host: tmp[0].toLowerCase(), port: parseInt(tmp[1])});
        }
      });
    }
    return sentinels.sort((i1, i2) => ((i1.host.toLowerCase()) > i2.host.toLowerCase() || i1.port - i2.port));
  }
  catch (e) {
    throw new Error('Invalid type for key ' + key + ': Cannot parse redis sentinels string - ' + e.message );
  }
}
function parseRedisSentinel(key, sentinelsString) {
  if (!sentinelsString) return [];

  // convert array entries from string to object if needed
  if (Array.isArray(sentinelsString)) {
    sentinelsString.forEach(function(entry, index) {
      if (typeof entry === 'string') {
        let tmp = entry.trim().split(':');
        sentinelsString[index] = {host: tmp[0].toLowerCase(), port: parseInt(tmp[1])};
      }
    });
    return sentinelsString.sort((i1, i2) => ((i1.host.toLowerCase()) > i2.host.toLowerCase() || i1.port - i2.port));
  }

  if (typeof sentinelsString !== 'string') {
    throw new Error('Invalid type for key ' + key + ': must be either comma separated string with sentinels or list of them');
  }

  try {
    let sentinels = [];
    if (sentinelsString.startsWith('[')) {
      let obj = JSON.parse(sentinelsString);
      obj.forEach(function(sentinel) {
        if (typeof sentinel === 'object') sentinels.push(sentinel);
        else {
          let tmp = sentinel.trim().split(':');
          sentinels.push({host: tmp[0].toLowerCase(), port: parseInt(tmp[1])});
        }
      });
    }
    else {
      // simple string, comma separated list of host:port
      let obj = sentinelsString.split(',');
      obj.forEach(function(sentinel) {
        if (sentinel && sentinel.trim()) {
          let tmp = sentinel.trim().split(':');
          sentinels.push({host: tmp[0].toLowerCase(), port: parseInt(tmp[1])});
        }
      });
    }
    return sentinels.sort((i1, i2) => ((i1.host.toLowerCase()) > i2.host.toLowerCase() || i1.port - i2.port));
  }
  catch (e) {
    throw new Error('Invalid type for key ' + key + ': Cannot parse redis sentinels string - ' + e.message );
  }
}
function parseRedisSentinel ( key , sentinelsString ) { if ( ! sentinelsString ) return [ ] ; // convert array entries from string to object if needed if ( Array . isArray ( sentinelsString ) ) { sentinelsString . forEach ( function ( entry , index ) { if ( typeof entry === 'string' ) { let tmp = entry . trim ( ) . split ( ':' ) ; sentinelsString [ index ] = { host : tmp [ 0 ] . toLowerCase ( ) , port : parseInt ( tmp [ 1 ] ) } ; } } ) ; return sentinelsString . sort ( ( i1 , i2 ) => ( ( i1 . host . toLowerCase ( ) ) > i2 . host . toLowerCase ( ) || i1 . port - i2 . port ) ) ; } if ( typeof sentinelsString !== 'string' ) { throw new Error ( 'Invalid type for key ' + key + ': must be either comma separated string with sentinels or list of them' ) ; } try { let sentinels = [ ] ; if ( sentinelsString . startsWith ( '[' ) ) { let obj = JSON . parse ( sentinelsString ) ; obj . forEach ( function ( sentinel ) { if ( typeof sentinel === 'object' ) sentinels . push ( sentinel ) ; else { let tmp = sentinel . trim ( ) . split ( ':' ) ; sentinels . push ( { host : tmp [ 0 ] . toLowerCase ( ) , port : parseInt ( tmp [ 1 ] ) } ) ; } } ) ; } else { // simple string, comma separated list of host:port let obj = sentinelsString . split ( ',' ) ; obj . forEach ( function ( sentinel ) { if ( sentinel && sentinel . trim ( ) ) { let tmp = sentinel . trim ( ) . split ( ':' ) ; sentinels . push ( { host : tmp [ 0 ] . toLowerCase ( ) , port : parseInt ( tmp [ 1 ] ) } ) ; } } ) ; } return sentinels . sort ( ( i1 , i2 ) => ( ( i1 . host . toLowerCase ( ) ) > i2 . host . toLowerCase ( ) || i1 . port - i2 . port ) ) ; } catch ( e ) { throw new Error ( 'Invalid type for key ' + key + ': Cannot parse redis sentinels string - ' + e . message ) ; } }
Parse a string with redis sentinel names and ports to an objects as needed
by ioredis for connections.

Allowed formats are:
<ul>
<li>comma separeted list of <code>hostname:port</code> values, port is optional</li>
<li>JSON-String with list of <code>hostname:port</code> string entries</li>
<li>JSON-String with list of sentinel objects <code>{"host":"localhost", "port": 26379}</code>
</ul>

The return value is a list with sentinel objects, e.g.: <code>{"host":"localhost", "port": 26379}</code>.
The list is sorted (needed for easier comparision if this connection i already known)

@param {string} key configuration key
@param {string} sentinelsString string or list object to check for valid sentinel connetion data
@return {object} ioredis sentinel list
@private
Parse a string with redis sentinel names and ports to an objects as needed by ioredis for connections .