<commit_before>#include "include/redis_admin.h"


//TO-DO: When an operation fails, it should automatically detect whether there are
//Sentinels available and, if so, try to failover to another Redis Node.


void RedisAdmin::init(std::string hostname, int port, int timeout_seconds, int timeout_microseconds)
{
  struct timeval timeout = {timeout_seconds, timeout_microseconds};
  c = redisConnectWithTimeout(hostname.c_str(), port, timeout);

  if (c == NULL || c->err) {
    if (c == NULL)
    {
      throw RedisConnectionException( "Error: Cannot Allocate Redis Instance" );
    }
    else if (c->err)
    {
      std::string err_msg (c->errstr);
      err_msg = "Error:" + err_msg;
      throw RedisConnectionException( err_msg );
    }
  exit(1);
  }
}

bool RedisAdmin::process_std_string_reply(redisReply *reply)
{
  bool ret_val = false;
  if (reply->str) {
    if ( strcmp(reply->str, "OK") == 0 ) {
      ret_val = true;
    }
  }
  freeReplyObject(reply);
  reply = NULL;
  return ret_val;
}

bool RedisAdmin::process_std_int_reply(redisReply *reply)
{
  int reply_code = reply->integer;
  freeReplyObject(reply);
  reply = NULL;
  if (reply_code == 1) {
    return true;
  }
  return false;
}

int RedisAdmin::return_int_reply(redisReply *reply)
{
  int reply_code = reply->integer;
  freeReplyObject(reply);
  reply = NULL;
  return reply_code;
}

std::string RedisAdmin::return_string_reply(redisReply *reply)
{
  std::string reply_str (reply->str);
  freeReplyObject(reply);
  reply = NULL;
  return reply_str;
}

RedisAdmin::RedisAdmin(std::string hostname, int port)
{
  init(hostname, port, 5, 0);
}

RedisAdmin::RedisAdmin(std::string hostname, int port, int timeout_seconds, int timeout_microseconds)
{
  init(hostname, port, timeout_seconds, timeout_microseconds);
}

RedisAdmin::RedisAdmin(RedisConnChain current_connection)<commit_msg>Redis Fix for error returning null from string functions<commit_after>#include "include/redis_admin.h"


//TO-DO: When an operation fails, it should automatically detect whether there are
//Sentinels available and, if so, try to failover to another Redis Node.


void RedisAdmin::init(std::string hostname, int port, int timeout_seconds, int timeout_microseconds)
{
  struct timeval timeout = {timeout_seconds, timeout_microseconds};
  c = redisConnectWithTimeout(hostname.c_str(), port, timeout);

  if (c == NULL || c->err) {
    if (c == NULL)
    {
      throw RedisConnectionException( "Error: Cannot Allocate Redis Instance" );
    }
    else if (c->err)
    {
      std::string err_msg (c->errstr);
      err_msg = "Error:" + err_msg;
      throw RedisConnectionException( err_msg );
    }
  exit(1);
  }
}

bool RedisAdmin::process_std_string_reply(redisReply *reply)
{
  bool ret_val = false;
  if (reply->str) {
    if ( strcmp(reply->str, "OK") == 0 ) {
      ret_val = true;
    }
  }
  freeReplyObject(reply);
  reply = NULL;
  return ret_val;
}

bool RedisAdmin::process_std_int_reply(redisReply *reply)
{
  int reply_code = reply->integer;
  freeReplyObject(reply);
  reply = NULL;
  if (reply_code == 1) {
    return true;
  }
  return false;
}

int RedisAdmin::return_int_reply(redisReply *reply)
{
  int reply_code = reply->integer;
  freeReplyObject(reply);
  reply = NULL;
  return reply_code;
}

std::string RedisAdmin::return_string_reply(redisReply *reply)
{
  if (reply->str) {
    std::string reply_str (reply->str);
    freeReplyObject(reply);
    reply = NULL;
    return reply_str;
  }
  else {
    freeReplyObject(reply);
    reply = NULL;
    return "";
  }
}

RedisAdmin::RedisAdmin(std::string hostname, int port)
{
  init(hostname, port, 5, 0);
}

RedisAdmin::RedisAdmin(std::string hostname, int port, int timeout_seconds, int timeout_microseconds)
{
  init(hostname, port, timeout_seconds, timeout_microseconds);
}

RedisAdmin::RedisAdmin(RedisConnChain current_connection)
{'fraction_non_alphanumeric': 0.12050685285751228, 'fraction_numerical': 0.002585983966899405, 'mean_word_length': 4.219973009446694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '7277560', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1309, 'n_words': 316}