<commit_before>(function() {
    'use strict';

    var events = require('events'),
        redis = require('redis');

    var Confdis = function(opts) {

        if (!opts) return new Error('Options object not supplied');

        this.opts = opts;

        var requiredOpts = ['host', 'port', 'rootKey'];

        requiredOpts.forEach(function(val, i, arr) {
            if (!opts[val]) {
                return new Error(val + ' option required but not specified');
            }
        });

        this.redisHost = opts.host;
        this.redisPort = opts.port;

        this.config = null;
        this.db = null;
        this.pubsubDB = null;
        this.rootKey = null;

        this._PUB_SUFFIX = ":_changes";
        this._REDIS_CONNECT_MAX_ATTEMPTS = null;
        this._REDIS_CONNECT_TIMEOUT = false;
        this._REDIS_OFFLINE_QUEUE = false;

    };

    Confdis.prototype = new events.EventEmitter();

    Confdis.prototype.redisConnectOpts = function() {
        return {
            connect_timeout: this._REDIS_CONNECT_TIMEOUT,
            enable_offline_queue: this._REDIS_OFFLINE_QUEUE,
            max_attempts: this._REDIS_CONNECT_MAX_ATTEMPTS
        };
    };

    Confdis.prototype.connect = function(cb) {

        var self = this;

        if (!cb) return new Error('Callback function not supplied as last argument');

        if (!self.redisHost || !self.redisPort) {
            return cb(new Error('Host and port values must be provided'));
        }


        this.db = redis.createClient(self.redisPort, self.redisHost, this.redisConnectOpts());

        this.db.on('error', function(err) {
            self.emit('error', err);
            return cb(err);
        });

        this.db.on('ready', function() {
            self.emit('ready');
            return cb();
        });

    };

    Confdis.prototype.sync = function(cb) {
        var self = this;

        self.db.get(self.rootKey, function(err, reply) {
            if (!err) {
                return cb(null, reply);
            } else {
                self.emit('sync-error', err);
                return cb(err);
            }
        });
    };

    Confdis.prototype.save = function(cb) {

        var self = this;

        if (self.config) {
            self.db.set(self.rootKey, self.config, function(err, res) {<commit_msg>Don't sync an empty config.<commit_after>(function() {
    'use strict';

    var events = require('events'),
        redis = require('redis');

    var Confdis = function(opts) {

        if (!opts) return new Error('Options object not supplied');

        this.opts = opts;

        var requiredOpts = ['host', 'port', 'rootKey'];

        requiredOpts.forEach(function(val, i, arr) {
            if (!opts[val]) {
                return new Error(val + ' option required but not specified');
            }
        });

        this.redisHost = opts.host;
        this.redisPort = opts.port;

        this.config = null;
        this.db = null;
        this.pubsubDB = null;
        this.rootKey = null;

        this._PUB_SUFFIX = ":_changes";
        this._REDIS_CONNECT_MAX_ATTEMPTS = null;
        this._REDIS_CONNECT_TIMEOUT = false;
        this._REDIS_OFFLINE_QUEUE = false;

    };

    Confdis.prototype = new events.EventEmitter();

    Confdis.prototype.redisConnectOpts = function() {
        return {
            connect_timeout: this._REDIS_CONNECT_TIMEOUT,
            enable_offline_queue: this._REDIS_OFFLINE_QUEUE,
            max_attempts: this._REDIS_CONNECT_MAX_ATTEMPTS
        };
    };

    Confdis.prototype.connect = function(cb) {

        var self = this;

        if (!cb) return new Error('Callback function not supplied as last argument');

        if (!self.redisHost || !self.redisPort) {
            return cb(new Error('Host and port values must be provided'));
        }


        this.db = redis.createClient(self.redisPort, self.redisHost, this.redisConnectOpts());

        this.db.on('error', function(err) {
            self.emit('error', err);
            return cb(err);
        });

        this.db.on('ready', function() {
            self.emit('ready');
            return cb();
        });

    };

    Confdis.prototype.sync = function(cb) {
        var self = this;

        self.db.get(self.rootKey, function(err, reply) {
            if (!err) {
                if(reply) {
                  //TODO compare diff and return a list of changed keys?
                  self.config = reply;
                  return cb(null, reply);
                 }else{
                   err = new Error('config is empty, not syncing');
                   self.emit('sync-error', err);
                   return cb(err);
                 }
            } else {
                self.emit('sync-error', err);
                return cb(err);
            }
        });
    };

    Confdis.prototype.save = function(cb) {

        var self = this;

        if (self.config) {
            self.db.set(self.rootKey, self.config, function(err, res) {
{'fraction_non_alphanumeric': 0.12307692307692308, 'fraction_numerical': 0.0, 'mean_word_length': 1.7703375760929718, 'pattern_counts': {'":': 2, '<': 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': '3570088', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1427, 'n_words': 315}