29 RCSIDH(redis_h,
"$Id: ea3061098c4704c6f1e9f8770e24fd5309b719ce $")
31 #include <freeradius-devel/server/base.h>
32 #include <freeradius-devel/server/map.h>
33 #include <freeradius-devel/server/module.h>
36 #include <hiredis/hiredis.h>
43 #define MAX_REDIS_COMMAND_LEN 4096
44 #define MAX_REDIS_ARGS 256
46 #define REDIS_ERROR_MOVED_STR "MOVED"
47 #define REDIS_ERROR_ASK_STR "ASK"
48 #define REDIS_ERROR_TRY_AGAIN_STR "TRYAGAIN"
49 #define REDIS_ERROR_NO_SCRIPT_STR "NOSCRIPT"
50 #define REDIS_DEFAULT_PORT 6379
66 if (*reply) freeReplyObject(*reply);
133 #define REDIS_COMMON_CONFIG \
134 { FR_CONF_OFFSET_FLAGS("server", CONF_FLAG_REQUIRED | CONF_FLAG_MULTI, fr_redis_conf_t, hostname) }, \
135 { FR_CONF_OFFSET("port", fr_redis_conf_t, port), .dflt = "6379" }, \
136 { FR_CONF_OFFSET("database", fr_redis_conf_t, database), .dflt = "0" }, \
137 { FR_CONF_OFFSET("use_tls", fr_redis_conf_t, use_tls), .dflt = "no" }, \
138 { FR_CONF_OFFSET("use_cluster_map", fr_redis_conf_t, use_cluster_map), .dflt = "yes" }, \
139 { FR_CONF_OFFSET("username", fr_redis_conf_t, username) }, \
140 { FR_CONF_OFFSET_FLAGS("password", CONF_FLAG_SECRET, fr_redis_conf_t, password) }, \
141 { FR_CONF_OFFSET("max_nodes", fr_redis_conf_t, max_nodes), .dflt = "20" }, \
142 { FR_CONF_OFFSET("max_alt", fr_redis_conf_t, max_alt), .dflt = "3" }, \
143 { FR_CONF_OFFSET("max_redirects", fr_redis_conf_t, max_redirects), .dflt = "2" }
156 bool box_error,
bool shallow) CC_HINT(
nonnull(2,3));
159 request_t *request, redisReply *key, redisReply *op, redisReply *
value);
171 redisReply *
out[],
size_t out_len,
static void fr_redis_pipeline_free(redisReply *reply[], size_t num)
int fr_redis_reply_to_value_box(TALLOC_CTX *ctx, fr_value_box_t *out, redisReply *reply, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, bool box_error, bool shallow))
Convert a string or integer type to fr_value_box_t of specified type.
uint8_t max_nodes
Maximum number of cluster nodes to connect to.
fr_time_delta_t reconnection_delay
fr_table_num_sorted_t const redis_rcodes[]
bool use_cluster_map
use cluster map.
redisContext * handle
Hiredis context used when issuing commands.
char const * username
for acls.
uint32_t database
number on Redis server.
fr_time_delta_t connection_timeout
int fr_redis_tuple_from_map(TALLOC_CTX *pool, char const *out[], size_t out_len[], map_t *map)
Add a single map pair to an existing command string as three elements.
fr_redis_cluster_node_t * node
Node this connection is to.
uint16_t port
of Redis daemon.
void fr_redis_reply_print(fr_log_lvl_t lvl, redisReply *reply, request_t *request, int idx)
Print the response data in a useful treelike form.
size_t redis_reply_types_len
static void fr_redis_reply_free(redisReply **reply)
Wrap freeReplyObject so we consistently check for NULL pointers.
uint32_t max_redirects
Maximum number of times we can be redirected.
void fr_redis_version_print(void)
Print the version of libhiredis the server was built against.
uint32_t fr_redis_version_num(char const *version)
Convert version string into a 32bit unsigned integer for comparisons.
fr_redis_rcode_t fr_redis_command_status(fr_redis_conn_t *conn, redisReply *reply)
Check the reply for errors.
fr_table_num_sorted_t const redis_reply_types[]
fr_time_delta_t retry_delay
How long to wait when we received a -TRYAGAIN message.
char const ** hostname
of Redis server.
fr_redis_rcode_t fr_redis_pipeline_result(unsigned int *pipelined, fr_redis_rcode_t *rcode, redisReply *out[], size_t out_len, fr_redis_conn_t *conn)
Simplifies handling of pipelined commands with Redis cluster.
fr_redis_rcode_t
Codes are ordered inversely by priority.
@ REDIS_RCODE_RECONNECT
Transitory error, caller should retry the operation with a new connection.
@ REDIS_RCODE_SUCCESS
Operation was successful.
@ REDIS_RCODE_MOVE
Attempt operation on an alternative node with remap.
@ REDIS_RCODE_TRY_AGAIN
Try the operation again.
@ REDIS_RCODE_NO_SCRIPT
Script doesn't exist.
@ REDIS_RCODE_ASK
Attempt operation on an alternative node.
@ REDIS_RCODE_ERROR
Unrecoverable library/server error.
char const * password
to authenticate to Redis.
fr_redis_rcode_t fr_redis_get_version(char *out, size_t out_len, fr_redis_conn_t *conn)
Get the version of Redis running on the remote server.
uint32_t max_alt
Maximum alternative nodes to try.
uint32_t max_retries
Maximum number of times we attempt a command when receiving successive -TRYAGAIN messages.
int fr_redis_reply_to_map(TALLOC_CTX *ctx, map_list_t *out, request_t *request, redisReply *key, redisReply *op, redisReply *value)
Convert a pair of redis reply objects to a map.
Configuration parameters for a redis connection.
Connection handle, holding a redis context.
An element in a lexicographically sorted array of name to num mappings.
A time delta, a difference in time measured in nanoseconds.
static size_t char ** out