<commit_before>//
// Copyright (c) Telefonica I+D. All rights reserved.
//
//

var config = require('./config_base').dbrelayer;
var redis = require('redis');

var rcli = redis.createClient(redis.DEFAULT_PORT, config.redis_host);

function update(key, obj, cllbk) {
    var str; // aux var for stringify object properties
    var o_aux = {}; // auxiliar object to adapt to redis
    // redis client allows one depth level of nested objects, i.e. a plain object
    for(p in obj) {
        if(typeof obj[p] === 'object') {
             str = JSON.stringify(obj[p]);
            o_aux[p] = str;
        }
        else {
            o_aux[p] = obj[p];
        }
    }
    rcli.hmset(config.key_prefix + key, o_aux, function (err, res) {
        if (cllbk) cllbk(err, res);
    });
}

exports.update = update;
<commit_msg>add get data support (retireve)<commit_after>//
// Copyright (c) Telefonica I+D. All rights reserved.
//
//

var config = require('./config_base').dbrelayer;
var redis = require('redis');

var rcli = redis.createClient(redis.DEFAULT_PORT, config.redis_host);

function update(key, obj, cllbk) {
  'use strict';
  var str; // aux var for stringify object properties
  var o_aux = {}; // auxiliar object to adapt to redis
  var p;
  // redis client allows one depth level of nested objects, i.e. a plain object
  for (p in obj) {
    if (obj.hasOwnProperty(p) && typeof obj[p] === 'object') {
      str = JSON.stringify(obj[p]);
      o_aux[p] = str;
    } else {
      o_aux[p] = obj[p];
    }
  }
  rcli.hmset(config.key_prefix + key, o_aux, function(err, res) {
    if (cllbk) {
      cllbk(err, res);
    }
  });
}

function get_data(key, callback) {
  'use strict';
  rcli.hgetall(config.key_prefix + key, function(err, data){
    if(err){
      callback(err);
    }
    else{
      callback(null, data);
    }
  });
}
exports.update = update;
exports.get_data = get_data;

{'fraction_non_alphanumeric': 0.1473851030110935, 'fraction_numerical': 0.0, 'mean_word_length': 2.69921875, 'pattern_counts': {'":': 0, '<': 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': '1913520', 'n_tokens_mistral': 668, 'n_tokens_neox': 669, 'n_words': 178}