<commit_before>// Load modules

var Redis = require('redis');
var Hoek = require('hoek');


// Declare internals

var internals = {};


exports.Connection = internals.Connection = function (options) {

    Hoek.assert(this.constructor === internals.Connection, 'Redis cache client must be instantiated using new');

    this.settings = options;
    this.client = null;
    return this;
};


internals.Connection.prototype.start = function (callback) {

    var self = this;
    if (this.client) {
        return callback();
    }

    this.client = Redis.createClient(this.settings.port, this.settings.host);

    if (this.settings.password) {
        this.client.auth(this.settings.password);
    }

    // Listen to errors

    var wasHandled = false;

    this.client.on('error', function (err) {

        if (wasHandled === false) {
            wasHandled = true;
            self.client = null;                                                     // Set to null so that Connnection.isReady returns false
            return callback(err);
        }
    });

    // Wait for connection

    this.client.on('connect', function () {

        if (wasHandled === false) {
            wasHandled = true;
            return callback();
        }
    });
};


internals.Connection.prototype.stop = function () {

    if (this.client) {
        this.client.quit();
        this.client = null;
    }
};


internals.Connection.prototype.isReady = function () {

    return (!!this.client);
};


internals.Connection.prototype.validateSegmentName = function (name) {

    if (!name) {<commit_msg>potential leak<commit_after>// Load modules

var Redis = require('redis');
var Hoek = require('hoek');


// Declare internals

var internals = {};


exports.Connection = internals.Connection = function (options) {

    Hoek.assert(this.constructor === internals.Connection, 'Redis cache client must be instantiated using new');

    this.settings = options;
    this.client = null;
    return this;
};


internals.Connection.prototype.start = function (callback) {

    var self = this;
    if (this.client) {
        return callback();
    }

    this.client = Redis.createClient(this.settings.port, this.settings.host);

    if (this.settings.password) {
        this.client.auth(this.settings.password);
    }

    // Listen to errors

    var wasHandled = false;

    this.client.on('error', function (err) {

        if (wasHandled === false) {
            wasHandled = true;
            self.client = null;                                                     // Set to null so that Connnection.isReady returns false
            return callback(err);
        }
    });

    // Wait for connection

    this.client.on('connect', function () {

        if (wasHandled === false) {
            wasHandled = true;
            return callback();
        }
    });
};


internals.Connection.prototype.stop = function () {

    if (this.client) {
        this.client.removeAllListeners();
        this.client.quit();
        this.client = null;
    }
};


internals.Connection.prototype.isReady = function () {

    return (!!this.client);
};


internals.Connection.prototype.validateSegmentName = function (name) {

    if (!name) {
{'fraction_non_alphanumeric': 0.12705809257533396, 'fraction_numerical': 0.0, 'mean_word_length': 2.1976166832174777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3456554', 'n_tokens_mistral': 931, 'n_tokens_neox': 882, 'n_words': 208}