</connection>
</connections>
<params>
- <param name="debug" value="1"/>
+ <param name="ignore-connect-fail" value="true"/>
</params>
</profile>
</profiles>
return NULL;
}
-switch_status_t hiredis_profile_create(hiredis_profile_t **new_profile, char *name, uint8_t port)
+switch_status_t hiredis_profile_create(hiredis_profile_t **new_profile, char *name, uint8_t ignore_connect_fail)
{
hiredis_profile_t *profile = NULL;
switch_memory_pool_t *pool = NULL;
profile->pool = pool;
profile->name = name ? switch_core_strdup(profile->pool, name) : "default";
profile->conn_head = NULL;
+ profile->ignore_connect_fail = ignore_connect_fail;
switch_core_hash_insert(mod_hiredis_globals.profiles, name, (void *) profile);
return SWITCH_STATUS_GENERR;
}
}
- return SWITCH_STATUS_GENERR;
+ return SWITCH_STATUS_SOCKERR;
}
if ( (profiles = switch_xml_child(cfg, "profiles")) != NULL) {
for (profile = switch_xml_child(profiles, "profile"); profile; profile = profile->next) {
hiredis_profile_t *new_profile = NULL;
- int debug = 0;
+ uint8_t ignore_connect_fail = 0;
char *name = (char *) switch_xml_attr_soft(profile, "name");
// Load params
if ( (params = switch_xml_child(profile, "params")) != NULL) {
for (param = switch_xml_child(params, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
- if ( ! strncmp(var, "debug", 5) ) {
- debug = atoi(switch_xml_attr_soft(param, "value"));
+ if ( !strncmp(var, "ignore-connect-fail", 19) ) {
+ ignore_connect_fail = switch_true(switch_xml_attr_soft(param, "value"));
}
}
}
- if ( hiredis_profile_create(&new_profile, name, debug) == SWITCH_STATUS_SUCCESS) {
+ if ( hiredis_profile_create(&new_profile, name, ignore_connect_fail) == SWITCH_STATUS_SUCCESS ) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created profile[%s]\n", name);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create profile[%s]\n", name);
} else if ( !strncmp(var, "port", 4) ) {
port = atoi(switch_xml_attr_soft(param, "value"));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "hiredis: adding conn[%u == %s]\n", port, switch_xml_attr_soft(param, "value"));
- } else if ( !strncmp(var, "timeout_ms", 10) ) {
+ } else if ( !strncmp(var, "timeout-ms", 10) || !strncmp(var, "timeout_ms", 10) ) {
timeout_ms = atoi(switch_xml_attr_soft(param, "value"));
} else if ( !strncmp(var, "password", 8) ) {
password = (char *) switch_xml_attr_soft(param, "value");
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
-* Copyright (C) 2005-2012, Anthony Minessale II <anthm@freeswitch.org>
+* Copyright (C) 2005-2016, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
*
* Contributor(s):
* William King <william.king@quentustech.com>
+* Chris Rienzo <chris.rienzo@citrix.com>
*
* mod_hiredis.c -- Redis DB access module
*
hashkey = switch_mprintf("incr %s", limit_key);
- if ( hiredis_profile_execute_sync(profile, hashkey, &response) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hiredis: profile[%s] error executing [%s] because [%s]\n", realm, hashkey, response);
- switch_channel_set_variable(channel, "hiredis_raw_response", response);
+ if ( (status = hiredis_profile_execute_sync(profile, hashkey, &response)) != SWITCH_STATUS_SUCCESS ) {
+ if ( status == SWITCH_STATUS_SOCKERR && profile->ignore_connect_fail ) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hiredis: ignoring profile[%s] connection error executing [%s]\n", realm, hashkey);
+ switch_goto_status(SWITCH_STATUS_SUCCESS, done);
+ }
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hiredis: profile[%s] error executing [%s] because [%s]\n", realm, hashkey, response ? response : "");
+ switch_channel_set_variable(channel, "hiredis_raw_response", response ? response : "");
switch_goto_status(SWITCH_STATUS_GENERR, done);
}
hashkey = switch_mprintf("decr %s", limit_pvt->limit_key);
- if ( hiredis_profile_execute_sync(profile, hashkey, &response) != SWITCH_STATUS_SUCCESS) {
+ if ( ( status = hiredis_profile_execute_sync(profile, hashkey, &response) ) != SWITCH_STATUS_SUCCESS ) {
+ if ( status == SWITCH_STATUS_SOCKERR && profile->ignore_connect_fail ) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hiredis: ignoring profile[%s] connection error executing [%s]\n", realm, hashkey);
+ switch_goto_status(SWITCH_STATUS_SUCCESS, done);
+ }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hiredis: profile[%s] error executing [%s] because [%s]\n", realm, hashkey, response);
switch_channel_set_variable(channel, "hiredis_raw_response", response);
switch_goto_status(SWITCH_STATUS_GENERR, done);
typedef struct mod_hiredis_global_s {
switch_memory_pool_t *pool;
switch_hash_t *profiles;
- uint8_t debug;
} mod_hiredis_global_t;
extern mod_hiredis_global_t mod_hiredis_globals;
typedef struct hiredis_profile_s {
switch_memory_pool_t *pool;
char *name;
- int debug;
+ uint8_t ignore_connect_fail;
hiredis_connection_t *conn_head;
} hiredis_profile_t;
} hiredis_limit_pvt_t;
switch_status_t mod_hiredis_do_config();
-switch_status_t hiredis_profile_create(hiredis_profile_t **new_profile, char *name, uint8_t port);
+switch_status_t hiredis_profile_create(hiredis_profile_t **new_profile, char *name, uint8_t ignore_connect_fail);
switch_status_t hiredis_profile_destroy(hiredis_profile_t **old_profile);
switch_status_t hiredis_profile_connection_add(hiredis_profile_t *profile, char *host, char *password, uint32_t port, uint32_t timeout_ms, uint32_t max_connections);