<commit_before>'use strict';

/*!
 * Module dependencies
 */
require('es6-shim');
var debug = require('debug')('loopback:connector:ioredis');

var Redis = require('ioredis');
var util = require('util');
var Connector = require('loopback-connector').Connector;
var httpError = require('http-errors');
var Promise = require('bluebird');
var uuid = require('node-uuid');

/**
 * Initialize the ioredis connector for the given data source
 *
 * @param {DataSource} dataSource The data source instance
 * @param {Function} [callback] The callback function
 */
exports.initialize = function initializeDataSource(dataSource, callback) {
  var settings = dataSource.settings;

  dataSource.connector = new IORedis(settings, dataSource);

  // Though not mentioned, `dataSource.setup()` assumes it's connected when `initialize()` is done.
  debug('Initialize and connect');
  dataSource.connector.connect(callback);
};

exports.IORedis = IORedis;

/**
 * The constructor for IORedis connector
 *
 * @param {Object} settings The settings object
 * @param {DataSource} dataSource The data source instance
 * @constructor
 * @see https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
 */
function IORedis(settings, dataSource) {
  Connector.call(this, 'ioredis', settings);

  // Copied from `loopback-connector-redis`.
  if (settings.url) {
    var url = require('url');
    var redisUrl = url.parse(settings.url);
    var redisAuth = (redisUrl.auth || '').split(':');
    settings.host = redisUrl.hostname;
    settings.port = redisUrl.port;
    if (redisAuth.length > 1) {
      settings.db = redisAuth[0];
      settings.password = <PASSWORD>Auth.slice(1).join(':');
    }
  }

  debug('Settings: %j', settings);
  this.dataSource = dataSource;
  this.Redis = Redis;
}

util.inherits(IORedis, Connector);

/**
 * Connect to IORedis
 *<commit_msg>add sentinel support - added a `sentinelMasterName` setting to map to `name` - needs a `sentinels` array setting<commit_after>'use strict';

/*!
 * Module dependencies
 */
require('es6-shim');
var debug = require('debug')('loopback:connector:ioredis');

var Redis = require('ioredis');
var util = require('util');
var Connector = require('loopback-connector').Connector;
var httpError = require('http-errors');
var Promise = require('bluebird');
var uuid = require('node-uuid');

/**
 * Initialize the ioredis connector for the given data source
 *
 * @param {DataSource} dataSource The data source instance
 * @param {Function} [callback] The callback function
 */
exports.initialize = function initializeDataSource(dataSource, callback) {
  var settings = dataSource.settings;

  dataSource.connector = new IORedis(settings, dataSource);

  // Though not mentioned, `dataSource.setup()` assumes it's connected when `initialize()` is done.
  debug('Initialize and connect');
  dataSource.connector.connect(callback);
};

exports.IORedis = IORedis;

/**
 * The constructor for IORedis connector
 *
 * @param {Object} settings The settings object
 * @param {DataSource} dataSource The data source instance
 * @constructor
 * @see https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
 */
function IORedis(settings, dataSource) {
  Connector.call(this, 'ioredis', settings);

  // Copied from `loopback-connector-redis`.
  if (settings.url) {
    var url = require('url');
    var redisUrl = url.parse(settings.url);
    var redisAuth = (redisUrl.auth || '').split(':');
    settings.host = redisUrl.hostname;
    settings.port = redisUrl.port;
    if (redisAuth.length > 1) {
      settings.db = redisAuth[0];
      settings.password = <PASSWORD>Auth.slice(1).join(':');
    }
  }

  if (settings.sentinels) {
    settings.name = settings.sentinelMasterName;
  }

  debug('Settings: %j', settings);
  this.dataSource = dataSource;
  this.Redis = Redis;
}

util.inherits(IORedis, Connector);

/**
 * Connect to IORedis
 *
{'fraction_non_alphanumeric': 0.1441741357234315, 'fraction_numerical': 0.00204865556978233, 'mean_word_length': 4.432545201668985, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4773466', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1202, 'n_words': 301}