<commit_before>
const moment = require('moment');
const redis = require('redis');

module.exports = (options, rateLimitType) => {
  const logger = options.logger || { log: (func, msg) => console[func](msg) };
  const rateLimits = options.rateLimits[rateLimitType];
  const timestampName = `${rateLimitType}TimeStamp`;
  const countName = `${rateLimitType}Count`;

  const WINDOW_SIZE_IN_MINUTES = rateLimits.windowSizeInMinutes;
  const MAX_WINDOW_REQUEST_COUNT = rateLimits.maxWindowRequestCount;
  const WINDOW_LOG_INTERVAL_IN_MINUTES = rateLimits.windowLogIntervalInMinutes;
  const ERROR_CODE = rateLimits.errCode;

  return async (req, res, next) => {
    const redisClient = redis.createClient();

    // check that redis client exists
    if (!redisClient) {
      logger.log('error', 'Redis client does not exist!');
      return next();
    }

    const closeConnection = async err => {
      await redisClient.quit();
      return next(err);
    };

    try {
      // fetch records of current user using IP address, returns null when no record is found
      return await redisClient.get(req.ip, async (err, record) => {
        if (err) {
          logger.log('error', `Error with requesting redis session for rate limiting: ${err}`);
          return await closeConnection();
        }<commit_msg>pass your host and port parameters to redis creatClient<commit_after>
const moment = require('moment');
const redis = require('redis');
const config = require('./../config/hof-defaults');

module.exports = (options, rateLimitType) => {
  const logger = options.logger || { log: (func, msg) => console[func](msg) };
  const rateLimits = options.rateLimits[rateLimitType];
  const timestampName = `${rateLimitType}TimeStamp`;
  const countName = `${rateLimitType}Count`;

  const WINDOW_SIZE_IN_MINUTES = rateLimits.windowSizeInMinutes;
  const MAX_WINDOW_REQUEST_COUNT = rateLimits.maxWindowRequestCount;
  const WINDOW_LOG_INTERVAL_IN_MINUTES = rateLimits.windowLogIntervalInMinutes;
  const ERROR_CODE = rateLimits.errCode;

  return async (req, res, next) => {
    const redisClient = redis.createClient(config.redis);

    // check that redis client exists
    if (!redisClient) {
      logger.log('error', 'Redis client does not exist!');
      return next();
    }

    const closeConnection = async err => {
      await redisClient.quit();
      return next(err);
    };

    try {
      // fetch records of current user using IP address, returns null when no record is found
      return await redisClient.get(req.ip, async (err, record) => {
        if (err) {
          logger.log('error', `Error with requesting redis session for rate limiting: ${err}`);
          return await closeConnection();
        }
{'fraction_non_alphanumeric': 0.11518708730741012, 'fraction_numerical': 0.0, 'mean_word_length': 3.709844559585492, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1522419', 'n_tokens_mistral': 813, 'n_tokens_neox': 805, 'n_words': 223}