The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
Functions | Variables
redis.c File Reference

Common functions for interacting with Redis via hiredis. More...

#include <freeradius-devel/redis/base.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/value.h>
#include "attrs.h"
+ Include dependency graph for redis.c:

Go to the source code of this file.

Functions

static int _redis_dict_free (UNUSED void *uctx)
 
static int _redis_dict_init (UNUSED void *uctx)
 
fr_redis_rcode_t fr_redis_command_status (fr_redis_conn_t *conn, redisReply *reply)
 Check the reply for errors.
 
fr_redis_rcode_t fr_redis_parse_version (char *out, size_t out_len, redisReply *reply)
 Parse the reply from the Redis command INFO SERVER to extract the version.
 
void fr_redis_reply_print (fr_log_lvl_t lvl, redisReply *reply, request_t *request, int idx, fr_redis_rcode_t status)
 Print the response data in a useful treelike form.
 
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.
 
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.
 
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.
 
uint32_t fr_redis_version_num (char const *version)
 Convert version string into a 32bit unsigned integer for comparisons.
 
void fr_redis_version_print (void)
 Print the version of libhiredis the server was built against.
 
int redis_dict_init (void)
 Load the Redis dictionaries.
 

Variables

fr_dict_attr_t const * attr_redis_bootstrap_node
 
fr_dict_attr_t const * attr_redis_bootstrap_port
 
fr_dict_attr_t const * attr_redis_cluster_id
 
fr_dict_attr_t const * attr_redis_force_update
 
fr_dict_attr_t const * attr_redis_log_prefix
 
fr_dict_attr_t const * attr_redis_max_nodes
 
fr_dict_attr_t const * attr_redis_node
 
fr_dict_attr_t const * attr_redis_node_endpoint
 
fr_dict_attr_t const * attr_redis_node_port
 
fr_dict_attr_t const * attr_redis_node_role
 
fr_dict_attr_t const * attr_redis_packet_type
 
fr_dict_attr_t const * attr_redis_password
 
fr_dict_attr_t const * attr_redis_shard
 
fr_dict_attr_t const * attr_redis_slot
 
fr_dict_attr_t const * attr_redis_slot_end
 
fr_dict_attr_t const * attr_redis_slot_start
 
fr_dict_attr_t const * attr_redis_tls_conf
 
fr_dict_attr_t const * attr_redis_use_tls
 
fr_dict_attr_t const * attr_redis_username
 
fr_dict_t const * dict_redis
 
fr_dict_autoload_t redis_base_dict []
 
fr_dict_attr_autoload_t redis_base_dict_attr []
 
fr_table_num_sorted_t const redis_rcodes []
 
size_t redis_rcodes_len = NUM_ELEMENTS(redis_rcodes)
 
fr_table_num_sorted_t const redis_reply_types []
 
size_t redis_reply_types_len = NUM_ELEMENTS(redis_reply_types)
 

Detailed Description

Common functions for interacting with Redis via hiredis.

Id
bca3149ba622d82e25bb6a483a25f5f3fb5bc29b

Definition in file redis.c.

Function Documentation

◆ _redis_dict_free()

static int _redis_dict_free ( UNUSED void *  uctx)
static

Definition at line 127 of file redis.c.

+ Here is the caller graph for this function:

◆ _redis_dict_init()

static int _redis_dict_init ( UNUSED void *  uctx)
static

Definition at line 112 of file redis.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_redis_command_status()

fr_redis_rcode_t fr_redis_command_status ( fr_redis_conn_t conn,
redisReply *  reply 
)

Check the reply for errors.

Parameters
[in]connused to issue the command.
[in]replyto process.
Returns
  • REDIS_RCODE_TRY_AGAIN - If the operation should be retries.
  • REDIS_RCODE_MOVE - If the key has been permanently moved.
  • REDIS_RCODE_ASK - If the key has been temporarily moved.
  • REDIS_RCODE_SUCCESS - if no errors.
  • REDIS_RCODE_ERROR - on command/server error.
  • REDIS_RCODE_NO_SCRIPT - script specified by evalsha doesn't exist.
  • REDIS_RCODE_RECONNECT - on connection error (probably needs reconnecting).

Definition at line 158 of file redis.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_redis_parse_version()

fr_redis_rcode_t fr_redis_parse_version ( char *  out,
size_t  out_len,
redisReply *  reply 
)

Parse the reply from the Redis command INFO SERVER to extract the version.

Parameters
[out]outWhere to write the version string.
[in]out_lenLength of the version string buffer.
[in]replyRedis reply to parse
Returns

Definition at line 611 of file redis.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_redis_reply_print()

void fr_redis_reply_print ( fr_log_lvl_t  lvl,
redisReply *  reply,
request_t request,
int  idx,
fr_redis_rcode_t  status 
)

Print the response data in a useful treelike form.

Parameters
[in]lvlto print data at.
[in]replyto print.
[in]requestThe current request.
[in]idxResponse number.
[in]statuscode from processing last reply.

Definition at line 229 of file redis.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_redis_reply_to_map()

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.

The maps can then be applied using map_to_request.

Parameters
[in,out]ctxto allocate maps in.
[out]outWhere to write the head of the new maps list.
[in]requestThe current request.
[in]keyto process.
[in]opto process.
[in]valueto process.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 457 of file redis.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_redis_reply_to_value_box()

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.

Will work with REDIS_REPLY_STRING (which is converted to FR_TYPE_STRING then cast to dst_type), or REDIS_REPLY_INTEGER (which is converted to FR_TYPE_UINT64, then cast to dst_type).

Note
Any unsupported types will trigger an assert. You must check the reply type prior to calling this function.
Parameters
[in,out]ctxto allocate any buffers in.
[out]outWhere to write the cast type.
[in]replyto process.
[in]dst_typeto convert to. May be FR_TYPE_VOID to infer type.
[in]dst_enumvUsed to convert string types to integers for attribute with enumerated values.
[in]box_errorIf true then REDIS_REPLY_ERROR will be copied to a box, otherwise we'll return and error with the contents of the error available on the thread local error stack.
[in]shallowIf true, we shallow copy strings.
Returns
  • 1 if we received a NIL reply.
  • 0 on success.
  • -1 on cast or parse failure.

Definition at line 298 of file redis.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_redis_tuple_from_map()

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.

  • Integer types will be encoded as integers.
  • Strings and octets will be encoded in their raw form.
  • Other types will be converted to their printable form and will be encoded as strings.
Note
lhs must be a TMPL_TYPE_ATTR.
rhs must be a TMPL_TYPE_DATA.
Parameters
poolto allocate any buffers in.
outWhere to write pointers to the member of the tuple. Unused elements should be a multiple of three, and it should have at least three unused elements.
out_lenWhere to write the size of the data pointed to by the equivalent index in the out array.
mapto convert.
Returns
0 on success. -1 on failure.

Definition at line 550 of file redis.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_redis_version_num()

uint32_t fr_redis_version_num ( char const *  version)

Convert version string into a 32bit unsigned integer for comparisons.

Parameters
[in]versionstring to parse.
Returns
32bit unsigned integer representing the version string.

Definition at line 643 of file redis.c.

+ Here is the caller graph for this function:

◆ fr_redis_version_print()

void fr_redis_version_print ( void  )

Print the version of libhiredis the server was built against.

Definition at line 107 of file redis.c.

+ Here is the caller graph for this function:

◆ redis_dict_init()

int redis_dict_init ( void  )

Load the Redis dictionaries.

Definition at line 136 of file redis.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ attr_redis_bootstrap_node

fr_dict_attr_t const* attr_redis_bootstrap_node

Definition at line 62 of file redis.c.

◆ attr_redis_bootstrap_port

fr_dict_attr_t const* attr_redis_bootstrap_port

Definition at line 63 of file redis.c.

◆ attr_redis_cluster_id

fr_dict_attr_t const* attr_redis_cluster_id

Definition at line 66 of file redis.c.

◆ attr_redis_force_update

fr_dict_attr_t const* attr_redis_force_update

Definition at line 75 of file redis.c.

◆ attr_redis_log_prefix

fr_dict_attr_t const* attr_redis_log_prefix

Definition at line 60 of file redis.c.

◆ attr_redis_max_nodes

fr_dict_attr_t const* attr_redis_max_nodes

Definition at line 61 of file redis.c.

◆ attr_redis_node

fr_dict_attr_t const* attr_redis_node

Definition at line 71 of file redis.c.

◆ attr_redis_node_endpoint

fr_dict_attr_t const* attr_redis_node_endpoint

Definition at line 72 of file redis.c.

◆ attr_redis_node_port

fr_dict_attr_t const* attr_redis_node_port

Definition at line 73 of file redis.c.

◆ attr_redis_node_role

fr_dict_attr_t const* attr_redis_node_role

Definition at line 74 of file redis.c.

◆ attr_redis_packet_type

fr_dict_attr_t const* attr_redis_packet_type

Definition at line 59 of file redis.c.

◆ attr_redis_password

fr_dict_attr_t const* attr_redis_password

Definition at line 65 of file redis.c.

◆ attr_redis_shard

fr_dict_attr_t const* attr_redis_shard

Definition at line 67 of file redis.c.

◆ attr_redis_slot

fr_dict_attr_t const* attr_redis_slot

Definition at line 68 of file redis.c.

◆ attr_redis_slot_end

fr_dict_attr_t const* attr_redis_slot_end

Definition at line 70 of file redis.c.

◆ attr_redis_slot_start

fr_dict_attr_t const* attr_redis_slot_start

Definition at line 69 of file redis.c.

◆ attr_redis_tls_conf

fr_dict_attr_t const* attr_redis_tls_conf

Definition at line 77 of file redis.c.

◆ attr_redis_use_tls

fr_dict_attr_t const* attr_redis_use_tls

Definition at line 76 of file redis.c.

◆ attr_redis_username

fr_dict_attr_t const* attr_redis_username

Definition at line 64 of file redis.c.

◆ dict_redis

fr_dict_t const* dict_redis

Definition at line 51 of file redis.c.

◆ redis_base_dict

fr_dict_autoload_t redis_base_dict
Initial value:
= {
{ .out = &dict_redis, .proto = "redis" },
}
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:311
fr_dict_t const * dict_redis
Definition redis.c:51

Definition at line 54 of file redis.c.

◆ redis_base_dict_attr

fr_dict_attr_autoload_t redis_base_dict_attr
Initial value:
= {
{ .out = &attr_redis_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_redis },
{ .out = &attr_redis_log_prefix, .name = "Log-Prefix", .type = FR_TYPE_STRING, .dict = &dict_redis },
{ .out = &attr_redis_max_nodes, .name = "Max-Nodes", .type = FR_TYPE_UINT8, .dict = &dict_redis },
{ .out = &attr_redis_bootstrap_node, .name = "Bootstrap-Node", .type = FR_TYPE_STRING, .dict = &dict_redis },
{ .out = &attr_redis_bootstrap_port, .name = "Bootstrap-Port", .type = FR_TYPE_UINT16, .dict = &dict_redis },
{ .out = &attr_redis_username, .name = "Username", .type = FR_TYPE_STRING, .dict = &dict_redis },
{ .out = &attr_redis_password, .name = "Password", .type = FR_TYPE_STRING, .dict = &dict_redis },
{ .out = &attr_redis_cluster_id, .name = "Cluster-Id", .type = FR_TYPE_UINT16, .dict = &dict_redis },
{ .out = &attr_redis_shard, .name = "Shard", .type = FR_TYPE_TLV, .dict = &dict_redis },
{ .out = &attr_redis_slot, .name = "Shard.Slot", .type = FR_TYPE_TLV, .dict = &dict_redis },
{ .out = &attr_redis_slot_start, .name = "Shard.Slot.Start", .type = FR_TYPE_UINT16, .dict = &dict_redis },
{ .out = &attr_redis_slot_end, .name = "Shard.Slot.End", .type = FR_TYPE_UINT16, .dict = &dict_redis },
{ .out = &attr_redis_node, .name = "Shard.Node", .type = FR_TYPE_TLV, .dict = &dict_redis },
{ .out = &attr_redis_node_endpoint, .name = "Shard.Node.Endpoint", .type = FR_TYPE_STRING, .dict = &dict_redis },
{ .out = &attr_redis_node_port, .name = "Shard.Node.Port", .type = FR_TYPE_UINT16, .dict = &dict_redis },
{ .out = &attr_redis_node_role, .name = "Shard.Node.Role", .type = FR_TYPE_UINT8, .dict = &dict_redis },
{ .out = &attr_redis_force_update, .name = "Force-Update", .type = FR_TYPE_BOOL, .dict = &dict_redis },
{ .out = &attr_redis_use_tls, .name = "Use-TLS", .type = FR_TYPE_BOOL, .dict = &dict_redis },
{ .out = &attr_redis_tls_conf, .name = "TLS-Conf", .type = FR_TYPE_UINT64, .dict = &dict_redis },
}
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_BOOL
A truth value.
fr_dict_attr_t const * attr_redis_node_role
Definition redis.c:74
fr_dict_attr_t const * attr_redis_bootstrap_node
Definition redis.c:62
fr_dict_attr_t const * attr_redis_use_tls
Definition redis.c:76
fr_dict_attr_t const * attr_redis_slot_end
Definition redis.c:70
fr_dict_attr_t const * attr_redis_force_update
Definition redis.c:75
fr_dict_attr_t const * attr_redis_packet_type
Definition redis.c:59
fr_dict_attr_t const * attr_redis_log_prefix
Definition redis.c:60
fr_dict_attr_t const * attr_redis_node
Definition redis.c:71
fr_dict_attr_t const * attr_redis_node_port
Definition redis.c:73
fr_dict_attr_t const * attr_redis_slot
Definition redis.c:68
fr_dict_attr_t const * attr_redis_slot_start
Definition redis.c:69
fr_dict_attr_t const * attr_redis_max_nodes
Definition redis.c:61
fr_dict_attr_t const * attr_redis_password
Definition redis.c:65
fr_dict_attr_t const * attr_redis_bootstrap_port
Definition redis.c:63
fr_dict_attr_t const * attr_redis_cluster_id
Definition redis.c:66
fr_dict_attr_t const * attr_redis_tls_conf
Definition redis.c:77
fr_dict_attr_t const * attr_redis_username
Definition redis.c:64
fr_dict_attr_t const * attr_redis_node_endpoint
Definition redis.c:72
fr_dict_attr_t const * attr_redis_shard
Definition redis.c:67

Definition at line 80 of file redis.c.

◆ redis_rcodes

fr_table_num_sorted_t const redis_rcodes[]
Initial value:
= {
{ L("ask"), REDIS_RCODE_ASK },
{ L("error"), REDIS_RCODE_ERROR },
{ L("move"), REDIS_RCODE_MOVE },
{ L("reconnect"), REDIS_RCODE_RECONNECT },
{ L("success"), REDIS_RCODE_SUCCESS },
{ L("try again"), REDIS_RCODE_TRY_AGAIN }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:228
@ REDIS_RCODE_RECONNECT
Transitory error, caller should retry the operation with a new connection.
Definition base.h:73
@ REDIS_RCODE_SUCCESS
Operation was successful.
Definition base.h:70
@ REDIS_RCODE_MOVE
Attempt operation on an alternative node with remap.
Definition base.h:76
@ REDIS_RCODE_TRY_AGAIN
Try the operation again.
Definition base.h:72
@ REDIS_RCODE_ASK
Attempt operation on an alternative node.
Definition base.h:75
@ REDIS_RCODE_ERROR
Unrecoverable library/server error.
Definition base.h:71

Definition at line 41 of file redis.c.

◆ redis_rcodes_len

size_t redis_rcodes_len = NUM_ELEMENTS(redis_rcodes)

Definition at line 49 of file redis.c.

◆ redis_reply_types

fr_table_num_sorted_t const redis_reply_types[]
Initial value:
= {
{ L("array"), REDIS_REPLY_ARRAY },
{ L("error"), REDIS_REPLY_ERROR },
{ L("integer"), REDIS_REPLY_INTEGER },
{ L("nil"), REDIS_REPLY_NIL },
{ L("status"), REDIS_REPLY_STATUS },
{ L("string"), REDIS_REPLY_STRING }
}

Definition at line 31 of file redis.c.

◆ redis_reply_types_len

size_t redis_reply_types_len = NUM_ELEMENTS(redis_reply_types)

Definition at line 39 of file redis.c.