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"
Go to the source code of this file.
|
| 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.
|
| |
Common functions for interacting with Redis via hiredis.
- Id
- bca3149ba622d82e25bb6a483a25f5f3fb5bc29b
- Copyright
- 2015 Arran Cudbard-Bell (a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg)
-
2000,2006,2015 The FreeRADIUS server project
-
2011 TekSavvy Solutions (gabe@.nosp@m.teks.nosp@m.avvy..nosp@m.com)
Definition in file redis.c.
◆ _redis_dict_free()
| static int _redis_dict_free |
( |
UNUSED void * |
uctx | ) |
|
|
static |
◆ _redis_dict_init()
| static int _redis_dict_init |
( |
UNUSED void * |
uctx | ) |
|
|
static |
◆ fr_redis_command_status()
Check the reply for errors.
- Parameters
-
| [in] | conn | used to issue the command. |
| [in] | reply | to 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.
◆ fr_redis_parse_version()
Parse the reply from the Redis command INFO SERVER to extract the version.
- Parameters
-
| [out] | out | Where to write the version string. |
| [in] | out_len | Length of the version string buffer. |
| [in] | reply | Redis reply to parse |
- Returns
-
Definition at line 611 of file redis.c.
◆ fr_redis_reply_print()
Print the response data in a useful treelike form.
- Parameters
-
| [in] | lvl | to print data at. |
| [in] | reply | to print. |
| [in] | request | The current request. |
| [in] | idx | Response number. |
| [in] | status | code from processing last reply. |
Definition at line 229 of file redis.c.
◆ 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] | ctx | to allocate maps in. |
| [out] | out | Where to write the head of the new maps list. |
| [in] | request | The current request. |
| [in] | key | to process. |
| [in] | op | to process. |
| [in] | value | to process. |
- Returns
- 0 on success.
- -1 on failure.
Definition at line 457 of file redis.c.
◆ fr_redis_reply_to_value_box()
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] | ctx | to allocate any buffers in. |
| [out] | out | Where to write the cast type. |
| [in] | reply | to process. |
| [in] | dst_type | to convert to. May be FR_TYPE_VOID to infer type. |
| [in] | dst_enumv | Used to convert string types to integers for attribute with enumerated values. |
| [in] | box_error | If 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] | shallow | If 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.
◆ 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
-
| pool | to allocate any buffers in. |
| out | Where 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_len | Where to write the size of the data pointed to by the equivalent index in the out array. |
| map | to convert. |
- Returns
- 0 on success. -1 on failure.
Definition at line 550 of file redis.c.
◆ 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] | version | string to parse. |
- Returns
- 32bit unsigned integer representing the version string.
Definition at line 643 of file redis.c.
◆ 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.
◆ redis_dict_init()
| int redis_dict_init |
( |
void |
| ) |
|
Load the Redis dictionaries.
Definition at line 136 of file redis.c.
◆ attr_redis_bootstrap_node
◆ attr_redis_bootstrap_port
◆ attr_redis_cluster_id
◆ attr_redis_force_update
◆ attr_redis_log_prefix
◆ attr_redis_max_nodes
◆ attr_redis_node
◆ attr_redis_node_endpoint
◆ attr_redis_node_port
◆ attr_redis_node_role
◆ attr_redis_packet_type
◆ attr_redis_password
◆ attr_redis_shard
◆ attr_redis_slot
◆ attr_redis_slot_end
◆ attr_redis_slot_start
◆ attr_redis_tls_conf
◆ attr_redis_use_tls
◆ attr_redis_username
◆ dict_redis
◆ redis_base_dict
Initial value:= {
}
#define DICT_AUTOLOAD_TERMINATOR
fr_dict_t const * dict_redis
Definition at line 54 of file redis.c.
◆ redis_base_dict_attr
Initial value:= {
}
@ 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
fr_dict_attr_t const * attr_redis_bootstrap_node
fr_dict_attr_t const * attr_redis_use_tls
fr_dict_attr_t const * attr_redis_slot_end
fr_dict_attr_t const * attr_redis_force_update
fr_dict_attr_t const * attr_redis_packet_type
fr_dict_attr_t const * attr_redis_log_prefix
fr_dict_attr_t const * attr_redis_node
fr_dict_attr_t const * attr_redis_node_port
fr_dict_attr_t const * attr_redis_slot
fr_dict_attr_t const * attr_redis_slot_start
fr_dict_attr_t const * attr_redis_max_nodes
fr_dict_attr_t const * attr_redis_password
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_tls_conf
fr_dict_attr_t const * attr_redis_username
fr_dict_attr_t const * attr_redis_node_endpoint
fr_dict_attr_t const * attr_redis_shard
Definition at line 80 of file redis.c.
◆ redis_rcodes
Initial value:= {
}
#define L(_str)
Helper for initialising arrays of string literals.
@ 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_ASK
Attempt operation on an alternative node.
@ REDIS_RCODE_ERROR
Unrecoverable library/server error.
Definition at line 41 of file redis.c.
◆ redis_rcodes_len
◆ 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