<commit_before>#ifndef __UTIL_H__
#define __UTIL_H__

#include <redismodule.h>
#include <stdarg.h>

/// make sure the response is not NULL or an error, and if it is sends the error to the client and
/// exit the current function
#define RMUTIL_ASSERT_NOERROR(ctx, r)                                   \
  if (r == NULL) {                                                      \
    return RedisModule_ReplyWithError(ctx, "ERR reply is NULL");        \
  } else if (RedisModule_CallReplyType(r) == REDISMODULE_REPLY_ERROR) { \
    RedisModule_ReplyWithCallReply(ctx, r);                             \
    return REDISMODULE_ERR;                                             \
  }

#define __rmutil_register_cmd(ctx, cmd, f, mode)                                \
  if (RedisModule_CreateCommand(ctx, cmd, f, mode, 1, 1, 1) == REDISMODULE_ERR) \
    return REDISMODULE_ERR;

#define RMUtil_RegisterReadCmd(ctx, cmd, f) __rmutil_register_cmd(ctx, cmd, f, "readonly")

#define RMUtil_RegisterWriteCmd(ctx, cmd, f) __rmutil_register_cmd(ctx, cmd, f, "write")

/* RedisModule utilities. */

/** DEPRECATED: Return the offset of an arg if it exists in the arg list, or 0 if it's not there */
int RMUtil_ArgExists(const char *arg, RedisModuleString **argv, int argc, int offset);

/* Same as argExists but returns -1 if not found. Use this, RMUtil_ArgExists is kept for backwards
compatibility. */
int RMUtil_ArgIndex(const char *arg, RedisModuleString **argv, int argc);

/**
Automatically conver the arg list to corresponding variable pointers according to a given format.
You pass it the command arg list and count, the starting offset, a parsing format, and pointers to
the variables.
The format is a string consisting of the following identifiers:<commit_msg>add RMUtil_RegisterWriteDenyOOMCmd<commit_after>#ifndef __UTIL_H__
#define __UTIL_H__

#include <redismodule.h>
#include <stdarg.h>

/// make sure the response is not NULL or an error, and if it is sends the error to the client and
/// exit the current function
#define RMUTIL_ASSERT_NOERROR(ctx, r)                                   \
  if (r == NULL) {                                                      \
    return RedisModule_ReplyWithError(ctx, "ERR reply is NULL");        \
  } else if (RedisModule_CallReplyType(r) == REDISMODULE_REPLY_ERROR) { \
    RedisModule_ReplyWithCallReply(ctx, r);                             \
    return REDISMODULE_ERR;                                             \
  }

#define __rmutil_register_cmd(ctx, cmd, f, mode)                                \
  if (RedisModule_CreateCommand(ctx, cmd, f, mode, 1, 1, 1) == REDISMODULE_ERR) \
    return REDISMODULE_ERR;

#define RMUtil_RegisterReadCmd(ctx, cmd, f) __rmutil_register_cmd(ctx, cmd, f, "readonly")

#define RMUtil_RegisterWriteCmd(ctx, cmd, f) __rmutil_register_cmd(ctx, cmd, f, "write")

#define RMUtil_RegisterWriteDenyOOMCmd(ctx, cmd, f) __rmutil_register_cmd(ctx, cmd, f, "write deny-oom")

/* RedisModule utilities. */

/** DEPRECATED: Return the offset of an arg if it exists in the arg list, or 0 if it's not there */
int RMUtil_ArgExists(const char *arg, RedisModuleString **argv, int argc, int offset);

/* Same as argExists but returns -1 if not found. Use this, RMUtil_ArgExists is kept for backwards
compatibility. */
int RMUtil_ArgIndex(const char *arg, RedisModuleString **argv, int argc);

/**
Automatically conver the arg list to corresponding variable pointers according to a given format.
You pass it the command arg list and count, the starting offset, a parsing format, and pointers to
the variables.
The format is a string consisting of the following identifiers:
{'fraction_non_alphanumeric': 0.08445667125171939, 'fraction_numerical': 0.002751031636863824, 'mean_word_length': 2.8314014752370915, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1145157', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1047, 'n_words': 381}