diff --git a/conf/vanilla/autoload_configs/hiredis.conf.xml b/conf/vanilla/autoload_configs/hiredis.conf.xml index 4288cb4c4f..e82453928b 100644 --- a/conf/vanilla/autoload_configs/hiredis.conf.xml +++ b/conf/vanilla/autoload_configs/hiredis.conf.xml @@ -16,7 +16,7 @@ - + diff --git a/src/mod/applications/mod_hiredis/hiredis_profile.c b/src/mod/applications/mod_hiredis/hiredis_profile.c index ce63d881d6..ca7164838a 100644 --- a/src/mod/applications/mod_hiredis/hiredis_profile.c +++ b/src/mod/applications/mod_hiredis/hiredis_profile.c @@ -93,7 +93,7 @@ static hiredis_context_t *hiredis_connection_get_context(hiredis_connection_t *c 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; @@ -105,6 +105,7 @@ switch_status_t hiredis_profile_create(hiredis_profile_t **new_profile, char *na 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); @@ -260,7 +261,7 @@ switch_status_t hiredis_profile_execute_sync(hiredis_profile_t *profile, const c return SWITCH_STATUS_GENERR; } } - return SWITCH_STATUS_GENERR; + return SWITCH_STATUS_SOCKERR; } diff --git a/src/mod/applications/mod_hiredis/hiredis_utils.c b/src/mod/applications/mod_hiredis/hiredis_utils.c index ad6d625e41..98995a08f9 100644 --- a/src/mod/applications/mod_hiredis/hiredis_utils.c +++ b/src/mod/applications/mod_hiredis/hiredis_utils.c @@ -45,20 +45,20 @@ switch_status_t mod_hiredis_do_config() 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); @@ -77,7 +77,7 @@ switch_status_t mod_hiredis_do_config() } 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"); diff --git a/src/mod/applications/mod_hiredis/mod_hiredis.c b/src/mod/applications/mod_hiredis/mod_hiredis.c index efe0a03443..1085f189c3 100644 --- a/src/mod/applications/mod_hiredis/mod_hiredis.c +++ b/src/mod/applications/mod_hiredis/mod_hiredis.c @@ -1,6 +1,6 @@ /* * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application -* Copyright (C) 2005-2012, Anthony Minessale II +* Copyright (C) 2005-2016, Anthony Minessale II * * Version: MPL 1.1 * @@ -23,6 +23,7 @@ * * Contributor(s): * William King +* Chris Rienzo * * mod_hiredis.c -- Redis DB access module * @@ -149,9 +150,13 @@ SWITCH_LIMIT_INCR(hiredis_limit_incr) 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); } @@ -212,7 +217,11 @@ SWITCH_LIMIT_RELEASE(hiredis_limit_release) 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); diff --git a/src/mod/applications/mod_hiredis/mod_hiredis.h b/src/mod/applications/mod_hiredis/mod_hiredis.h index 2403564b06..0b4c754575 100644 --- a/src/mod/applications/mod_hiredis/mod_hiredis.h +++ b/src/mod/applications/mod_hiredis/mod_hiredis.h @@ -8,7 +8,6 @@ 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; @@ -33,7 +32,7 @@ typedef struct hiredis_connection_s { 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; @@ -48,7 +47,7 @@ typedef struct hiredis_limit_pvt_s { } 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);