index.js
function _createClient (name, options, callback) {
  const log = logger.child({ redis: name })
  log.debug('Redis creating client: ' + name)
  let isReady = false

  const config = {}
  deepAssign(config, _defaults, options)
  let client = redis.createClient(config)

  callback = _once(callback)
  _clients[ name ] = client
  _clients[ name ].log = log

  log.debug({ clients: Object.keys(_clients) }, 'Redis clients')

  client.on('error', function (err) {
    log.error({ err: err }, 'Redis client error')
    callback(err)
  })

  client.on('warning', function (err) {
    log.warn({ err: err }, 'Redis client warning')
  })

  client.on('connect', function () {
    log.debug('Redis connected: ' + name)
  })

  client.on('ready', function () {
    log.debug('Redis client ready: ' + name)
    log.debug({ config: config }, 'Redis client config')
    log.debug(`Redis server version: ${safeGet(() => client.server_info.redis_version)}`)
    isReady = true
    callback(null, client)
  })

  client.on('reconnecting', function () {
    log.debug('Redis client reconnecting: ' + name)
  })

  client.on('end', function () {
    log.debug('Redis client end: ' + name)
    // Close the connection before removing reference.
    client.quit()
    client = null
    delete _clients[ name ]
    log.debug({ clients: Object.keys(_clients) }, 'Redis clients: ' + _clients.length)
    if (!isReady) {
      callback(new Error('Done - Failed to connect to Redis'))
    }
  })
}
function _createClient (name, options, callback) {
  const log = logger.child({ redis: name })
  log.debug('Redis creating client: ' + name)
  let isReady = false

  const config = {}
  deepAssign(config, _defaults, options)
  let client = redis.createClient(config)

  callback = _once(callback)
  _clients[ name ] = client
  _clients[ name ].log = log

  log.debug({ clients: Object.keys(_clients) }, 'Redis clients')

  client.on('error', function (err) {
    log.error({ err: err }, 'Redis client error')
    callback(err)
  })

  client.on('warning', function (err) {
    log.warn({ err: err }, 'Redis client warning')
  })

  client.on('connect', function () {
    log.debug('Redis connected: ' + name)
  })

  client.on('ready', function () {
    log.debug('Redis client ready: ' + name)
    log.debug({ config: config }, 'Redis client config')
    log.debug(`Redis server version: ${safeGet(() => client.server_info.redis_version)}`)
    isReady = true
    callback(null, client)
  })

  client.on('reconnecting', function () {
    log.debug('Redis client reconnecting: ' + name)
  })

  client.on('end', function () {
    log.debug('Redis client end: ' + name)
    // Close the connection before removing reference.
    client.quit()
    client = null
    delete _clients[ name ]
    log.debug({ clients: Object.keys(_clients) }, 'Redis clients: ' + _clients.length)
    if (!isReady) {
      callback(new Error('Done - Failed to connect to Redis'))
    }
  })
}
function _createClient ( name , options , callback ) { const log = logger . child ( { redis : name } ) log . debug ( 'Redis creating client: ' + name ) let isReady = false const config = { } deepAssign ( config , _defaults , options ) let client = redis . createClient ( config ) callback = _once ( callback ) _clients [ name ] = client _clients [ name ] . log = log log . debug ( { clients : Object . keys ( _clients ) } , 'Redis clients' ) client . on ( 'error' , function ( err ) { log . error ( { err : err } , 'Redis client error' ) callback ( err ) } ) client . on ( 'warning' , function ( err ) { log . warn ( { err : err } , 'Redis client warning' ) } ) client . on ( 'connect' , function ( ) { log . debug ( 'Redis connected: ' + name ) } ) client . on ( 'ready' , function ( ) { log . debug ( 'Redis client ready: ' + name ) log . debug ( { config : config } , 'Redis client config' ) log . debug ( ` ${ safeGet ( ( ) => client . server_info . redis_version ) } ` ) isReady = true callback ( null , client ) } ) client . on ( 'reconnecting' , function ( ) { log . debug ( 'Redis client reconnecting: ' + name ) } ) client . on ( 'end' , function ( ) { log . debug ( 'Redis client end: ' + name ) // Close the connection before removing reference. client . quit ( ) client = null delete _clients [ name ] log . debug ( { clients : Object . keys ( _clients ) } , 'Redis clients: ' + _clients . length ) if ( ! isReady ) { callback ( new Error ( 'Done - Failed to connect to Redis' ) ) } } ) }
Creates a Redis client based on the given name and options.
@param {*} name the given name for the Redis client.
@param {*} options the given options for the Redis client.
@param {*} callback
Creates a Redis client based on the given name and options .