diff --git a/src/modules/ndb_redis/redis_client.c b/src/modules/ndb_redis/redis_client.c index 9395773731d..520f32364bb 100644 --- a/src/modules/ndb_redis/redis_client.c +++ b/src/modules/ndb_redis/redis_client.c @@ -608,7 +608,7 @@ int redisc_exec_pipelined(redisc_server_t *rsrv) goto error_exec; } } - LM_DBG("reply is [%s]",rpl->rplRedis->str); + LM_DBG_redis_reply(rpl->rplRedis); /* replies are received just retrieve them */ for (i=1;ipiped.pending_commands;i++) @@ -625,7 +625,13 @@ int redisc_exec_pipelined(redisc_server_t *rsrv) LM_ERR("Unable to read reply\n"); continue; } - LM_DBG("reply is [%s]",rpl->rplRedis->str); + if (rpl->rplRedis == NULL) + { + LM_ERR("Trying to read reply for command %.*s but nothing in buffer!", + rsrv->piped.commands[i].len,rsrv->piped.commands[i].s); + continue; + } + LM_DBG_redis_reply(rpl->rplRedis); } redisc_free_pipelined_cmds(rsrv); rsrv->disable.consecutive_errors = 0; @@ -1061,3 +1067,57 @@ int redis_count_err_and_disable(redisc_server_t *rsrv) } return 0; } + +void print_redis_reply(int log_level, redisReply *rpl,int offset) +{ + int i; + char padding[MAXIMUM_NESTED_KEYS + 1]; + + if(!is_printable(log_level)) + return; + + if (!rpl) + { + LM_ERR("Unexpected null reply"); + return; + } + + if (offset > MAXIMUM_NESTED_KEYS) + { + LM_ERR("Offset is too big"); + return; + } + + for (i=0;itype) + { + case REDIS_REPLY_STRING: + LOG(log_level,"%sstring reply: [%s]", padding, rpl->str); + break; + case REDIS_REPLY_INTEGER: + LOG(log_level,"%sinteger reply: %lld", padding, rpl->integer); + break; + case REDIS_REPLY_ARRAY: + LOG(log_level,"%sarray reply with %d elements", padding, (int)rpl->elements); + for (i=0; i < rpl->elements; i++) + { + LOG(log_level,"%selement %d:",padding,i); + print_redis_reply(log_level,rpl->element[i],offset+1); + } + break; + case REDIS_REPLY_NIL: + LOG(log_level,"%snil reply",padding); + break; + case REDIS_REPLY_STATUS: + LOG(log_level,"%sstatus reply: %s", padding, rpl->str); + break; + case REDIS_REPLY_ERROR: + LOG(log_level,"%serror reply: %s", padding, rpl->str); + break; + } +} diff --git a/src/modules/ndb_redis/redis_client.h b/src/modules/ndb_redis/redis_client.h index 73cbd0b3c0f..50431cbc407 100644 --- a/src/modules/ndb_redis/redis_client.h +++ b/src/modules/ndb_redis/redis_client.h @@ -36,6 +36,7 @@ #define MAXIMUM_PIPELINED_COMMANDS 1000 #define MAXIMUM_NESTED_KEYS 10 +#define LM_DBG_redis_reply(rpl) print_redis_reply(L_DBG,(rpl),0) int redisc_init(void); int redisc_destroy(void); @@ -97,4 +98,5 @@ int redisc_free_reply(str *name); int redisc_check_auth(redisc_server_t *rsrv, char *pass); int redis_check_server(redisc_server_t *rsrv); int redis_count_err_and_disable(redisc_server_t *rsrv); +void print_redis_reply(int log_level, redisReply *rpl,int offset); #endif