<commit_before>import redis from 'redis';
import bluebird from 'bluebird';
import hash from 'object-hash';
import config from '../config';

bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);
let redisClientInstance;

function redisClient() {
  return new Promise((resolve, reject) => {
    if (redisClientInstance && redisClientInstance.connected) {
      return resolve(redisClientInstance);
    }
    const client = redis.createClient(config.REDIS_PORT, config.REDIS_HOST);
    client.on('error', reject);
    client.on('connect', () => {
      redisClientInstance = client;
      return resolve(client);
    });
  });
}

function saveToList(client, paramsHash, data) {
  return new Promise((resolve, reject) => {
    const multi = client.multi();
    for (let i = 0; i < data.length; i++) {
      console.log(data[i]);
      multi.rpush(paramsHash, data[i]);
    }
    multi.exec((errors, results) => {
      if (errors) reject(errors);
      resolve(results);
    });
  });<commit_msg>work with redis - stage4<commit_after>import redis from 'redis';
import bluebird from 'bluebird';
import hash from 'object-hash';
import config from '../config';

bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);
let redisClientInstance;

function redisClient() {
  return new Promise((resolve, reject) => {
    if (redisClientInstance && redisClientInstance.connected) {
      return resolve(redisClientInstance);
    }
    const client = redis.createClient(config.REDIS_PORT, config.REDIS_HOST);
    client.on('error', reject);
    client.on('connect', () => {
      redisClientInstance = client;
      return resolve(client);
    });
  });
}

function saveToList(client, paramsHash, data) {
  return new Promise((resolve, reject) => {
    try {
      for (let i = 0; i < data.length; i++) {
        client.rpush(paramsHash, data[i]);
        if (i === (data.length - 1)) resolve(true);
      }
    }
    catch(err) {
      reject(err);
    }
  });
{'fraction_non_alphanumeric': 0.1455260570304818, 'fraction_numerical': 0.0019665683382497543, 'mean_word_length': 3.67816091954023, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '2985678', 'n_tokens_mistral': 636, 'n_tokens_neox': 632, 'n_words': 139}