<commit_before>'use strict';

// todo: create store provider and register redis store only for node.js version

var CacheEntry = require('./CacheEntry');

// todo: switch to redis
// https://www.npmjs.org/package/redis
//noinspection JSHint
/**
 * Redis provider stub
 * @param host
 * @param port
 * @param db
 * @constructor
 */
// todo: change to options
function Redis(){
  this.get = function get(){};
  this.set = function set(){};
  this.delete = function del(){};
  this.flushdb = function clear(){};
  this.dbsize = function dbsize(){};
}

/**
 * Caching implementation that uses Redis as data storage.
 * @constructor
 * @param {string=} [host='localhost']
 * @param {number=} [port=6379]
 * @param {number=} [db=0]
 */
// todo: what about auth?
// todo: change to options
function RedisStore(host, port, db){
  host = host || 'localhost';
  port = port || 6379;
  db = db || 0;
  this.redis = new Redis(host, port, db);
}

RedisStore.prototype.get = function (key, cb){
  this.redis.get(key, function(err, entry){
    if (err || !entry){
      return cb(err);
    }
    return cb(null, CacheEntry.parse(JSON.parse(entry)));
  });
};

RedisStore.prototype.set = function (key, val, cb){
  var entry = JSON.stringify(val);
  this.redis.set(key, entry, cb);
};

RedisStore.prototype.delete = function (key, cb){
  this.redis.delete(key,cb);
};

RedisStore.prototype.clear = function (cb){
  // todo: check redis implementation of flushdb
  this.redis.flushdb(cb);
};

RedisStore.prototype.size = function (cb){
  this.redis.dbsize(cb);
};
<commit_msg>added Redis Store class<commit_after>'use strict';

// todo: create store provider and register redis store only for node.js version
var redis = require("redis");

var CacheEntry = require('./CacheEntry');

/**
 * Caching implementation that uses Redis as data storage.
 * @constructor
 * @param {string=} [host='localhost']
 * @param {number=} [port=6379]
 * @param {number=} [db=0]
 */
function RedisStore(opt){
  this._options = opt || {};
  this.redis = redis.createClient(opt.host, opt.port, opt.options);
  this.redis.debug_mode = /redis/i.test(process.env.DEBUG);
}

RedisStore.prototype.get = function (key, cb){
  this.redis.get(key, function(err, entry){
    return cb(err, !entry ? null : CacheEntry.parse(JSON.parse(entry)));
  });
};

RedisStore.prototype.set = function (key, val, cb){
  var entry = JSON.stringify(val);
  this.redis.set(key, entry, cb);
  if (this._options.ttl){
    this.redis.expire(key, this._options.ttl);
  }
};

RedisStore.prototype.delete = function (key, cb){
  this.redis.del(key, cb);
};

RedisStore.prototype.clear = function (cb){
  this.redis.flushdb(cb);
};

RedisStore.prototype.size = function (cb){
  this.redis.dbsize(cb);
};

module.exports = RedisStore;
{'fraction_non_alphanumeric': 0.16931982633863965, 'fraction_numerical': 0.005426917510853835, 'mean_word_length': 4.027272727272727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '1967318', 'n_tokens_mistral': 957, 'n_tokens_neox': 950, 'n_words': 238}