<commit_before>var redis = require('redis'),
    extend = require('extend'),
    log4js = require('log4js'),
    log = log4js.getLogger();

function logger(state) {
    var state = state;
    return function(type, message) {
        if (state) {
            log[type](message);
        }
    }
}

/**
 * Redis Event Subscriber
 * Subscribe to Redis Keyspace and Keyevent notification
 * @param config
 * @constructor
 */
function Revent(config) {
    if (!(this instanceof Revent)) {
        return new Revent(config);
    }

    //Require Redis if its not injected
    if (!redis || typeof redis !== 'object') {
        throw new Error('Not connected module Redis.');
    }

    this.params = extend(true, {
        host: 'localhost',
        port: 6379,
        db: 0,
        options: {},
        logger: false
    }, config || {});

    // config log
    this.log = logger(this.params.logger);
    this.log('info', 'Start init params: ' + JSON.stringify(this.params));

    this.receiver = redis.createClient(
        this.params.port,
        this.params.host,
        this.params.options);

    this.publisher = redis.createClient(
        this.params.port,
        this.params.host,
        this.params.options);

    this.receiver.select(this.params.db);
    this.publisher.select(this.params.db);

    if (this.params.auth) {
        this.receiver.auth(this.params.auth);
        this.publisher.auth(this.params.auth);
    }

    this.receiver.on("error", function(err) {
        this.log('error', 'Receiver error: ' + err);
    }.bind(this));

    this.publisher.on("error", function(err) {
        this.log('error', 'Publisher error: ' + err);
    }.bind(this));

    return this;
};

/**
 * Subscribe to a channel
 * @param {String} channel The channel to subscribe to, can be a pattern e.g. 'user.*'
 * @param {Array} params The array consists of the event name for the subscription and callback
 */
Revent.prototype.on = function(channel, params) {
    if (params === undefined || !Array.isArray(params)) {
        throw new Error('Wrong type argument callback.');
    }

    var _callback = params.pop(),
        _events = params,
        _key = ['__keyevent@', '__keyspace@'][+!!params.length] + this.params.db + '__:' + channel;

    this.receiver.on('pmessage', function(pattern, _channel, message) {
        console.log(pattern, _channel, message)
        if (pattern === _key) {
            this.log('debug',
                'Received message:\n' + 'pattern: ' + pattern + '\n' + 'channel: ' + _channel + '\n' + 'message: ' + message);

            if (_events.length && !!~_events.indexOf(message)) {
                _callback(message, _channel);
            } else if (_events[0] === 'all') {
                _callback(message, _channel);
            } else if (!_events.length) {
                _callback(message, _channel);
            }
        }
    }.bind(this));

    this.receiver.psubscribe(_key);
    this.log('info', 'Subscribe channel:' + _key);
    return this;
};
<commit_msg>console<commit_after>var redis = require('redis'),
    extend = require('extend'),
    log4js = require('log4js'),
    log = log4js.getLogger();

function logger(state) {
    var state = state;
    return function(type, message) {
        if (state) {
            log[type](message);
        }
    }
}

/**
 * Redis Event Subscriber
 * Subscribe to Redis Keyspace and Keyevent notification
 * @param config
 * @constructor
 */
function Revent(config) {
    if (!(this instanceof Revent)) {
        return new Revent(config);
    }

    //Require Redis if its not injected
    if (!redis || typeof redis !== 'object') {
        throw new Error('Not connected module Redis.');
    }

    this.params = extend(true, {
        host: 'localhost',
        port: 6379,
        db: 0,
        options: {},
        logger: false
    }, config || {});

    // config log
    this.log = logger(this.params.logger);
    this.log('info', 'Start init params: ' + JSON.stringify(this.params));

    this.receiver = redis.createClient(
        this.params.port,
        this.params.host,
        this.params.options);

    this.publisher = redis.createClient(
        this.params.port,
        this.params.host,
        this.params.options);

    this.receiver.select(this.params.db);
    this.publisher.select(this.params.db);

    if (this.params.auth) {
        this.receiver.auth(this.params.auth);
        this.publisher.auth(this.params.auth);
    }

    this.receiver.on("error", function(err) {
        this.log('error', 'Receiver error: ' + err);
    }.bind(this));

    this.publisher.on("error", function(err) {
        this.log('error', 'Publisher error: ' + err);
    }.bind(this));

    return this;
};

/**
 * Subscribe to a channel
 * @param {String} channel The channel to subscribe to, can be a pattern e.g. 'user.*'
 * @param {Array} params The array consists of the event name for the subscription and callback
 */
Revent.prototype.on = function(channel, params) {
    if (params === undefined || !Array.isArray(params)) {
        throw new Error('Wrong type argument callback.');
    }

    var _callback = params.pop(),
        _events = params,
        _key = ['__keyevent@', '__keyspace@'][+!!params.length] + this.params.db + '__:' + channel;

    this.receiver.on('pmessage', function(pattern, _channel, message) {
        if (pattern === _key) {
            this.log('debug',
                'Received message:\n' + 'pattern: ' + pattern + '\n' + 'channel: ' + _channel + '\n' + 'message: ' + message+'\n');

            if (_events.length && !!~_events.indexOf(message)) {
                _callback(message, _channel);
            } else if (_events[0] === 'all') {
                _callback(message, _channel);
            } else if (!_events.length) {
                _callback(message, _channel);
            }
        }
    }.bind(this));

    this.receiver.psubscribe(_key);
    this.log('info', 'Subscribe channel:' + _key);
    return this;
};

{'fraction_non_alphanumeric': 0.15380753138075315, 'fraction_numerical': 0.0030125523012552303, 'mean_word_length': 2.3877551020408165, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '543576', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1792, 'n_words': 423}