<commit_before>
/*!
 * Connect - Redis
 * Copyright(c) 2010 <NAME> <<EMAIL>>
 * MIT Licensed
 * Modifications by <NAME> <<EMAIL>>
 * 
 */

/**
 * Module dependencies.
 */

var Store = require('connect').session.Store;
var redis = require('./redisclient');

/**
 * Initialize RedisStore with the given `options`.
 *
 * @param {Object} options
 * @api public
 */

var RedisStore = module.exports = function RedisStore(options) {
  options = options || {};
  Store.call(this, options);
  this.client = redis.initSessionClient();
};

/**
 * Inherit from `Store`.
 */

RedisStore.prototype.__proto__ = Store.prototype;

/**
 * Attempt to fetch session by the given `hash`.
 *
 * @param {String} hash
 * @param {Function} fn
 * @api public
 */

RedisStore.prototype.get = function(hash, fn){
  this.client.get(hash, function(err, data){
    try {
      fn(null, data
        ? JSON.parse(data.toString())
        : data);
    } catch (err) {
      fn(err);
    } 
  });
};

/**
 * Commit the given `sess` object associated with the given `hash`.
 *
 * @param {String} hash
 * @param {Session} sess
 * @param {Function} fn
 * @api public
 */

RedisStore.prototype.set = function(hash, sess, fn){
  var self = this;
  try {
    this.client.setex(hash, self.maxAge / 1000 | 0, JSON.stringify(sess), function(){
      fn && fn.apply(this, arguments);
    });
  } catch (err) {
    fn && fn(err);
  } 
};

/**
 * Destroy the session associated with the given `hash`.<commit_msg>Logging for errors in redis session store.<commit_after>
/*!
 * Connect - Redis
 * Copyright(c) 2010 <NAME> <<EMAIL>>
 * MIT Licensed
 * Modifications by <NAME> <<EMAIL>>
 * 
 */

/**
 * Module dependencies.
 */

var Store = require('connect').session.Store;
var redis = require('./redisclient');

/**
 * Initialize RedisStore with the given `options`.
 *
 * @param {Object} options
 * @api public
 */

var RedisStore = module.exports = function RedisStore(options) {
  options = options || {};
  Store.call(this, options);
  this.client = redis.initSessionClient();
};

/**
 * Inherit from `Store`.
 */

RedisStore.prototype.__proto__ = Store.prototype;

/**
 * Attempt to fetch session by the given `hash`.
 *
 * @param {String} hash
 * @param {Function} fn
 * @api public
 */

RedisStore.prototype.get = function(hash, fn){
  this.client.get(hash, function(err, data){
    try {
      fn(null, data
        ? JSON.parse(data.toString())
        : data);
    } catch (err) {
      console.log("ERROR with RedisStore.get",err);
      fn(err);
    } 
  });
};

/**
 * Commit the given `sess` object associated with the given `hash`.
 *
 * @param {String} hash
 * @param {Session} sess
 * @param {Function} fn
 * @api public
 */

RedisStore.prototype.set = function(hash, sess, fn){
  var self = this;
  try {
    this.client.setex(hash, self.maxAge / 1000 | 0, JSON.stringify(sess), function(){
      fn && fn.apply(this, arguments);
    });
  } catch (err) {
    console.log("ERROR with RedisStore.set",err);
    fn && fn(err);
  } 
};

/**
 * Destroy the session associated with the given `hash`.
{'fraction_non_alphanumeric': 0.16737357259380098, 'fraction_numerical': 0.005872756933115824, 'mean_word_length': 3.0989304812834226, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '606069', 'n_tokens_mistral': 1033, 'n_tokens_neox': 1002, 'n_words': 267}