From 580011677c460165a0f3907879155a9a9d2b3891 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 17 Feb 2017 13:25:25 +0000 Subject: [PATCH] [Minor] Add routine to convert redis reply type to string Issue: #1228 --- src/libserver/redis_pool.c | 31 ++++++++++++++++++++++++++++ src/libserver/redis_pool.h | 7 +++++++ src/libstat/backends/redis_backend.c | 9 ++++---- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/libserver/redis_pool.c b/src/libserver/redis_pool.c index 5cb898648..0b7c30844 100644 --- a/src/libserver/redis_pool.c +++ b/src/libserver/redis_pool.c @@ -455,3 +455,34 @@ rspamd_redis_pool_destroy (struct rspamd_redis_pool *pool) g_slice_free1 (sizeof (*pool), pool); } + +const gchar* +rspamd_redis_type_to_string (int type) +{ + const gchar *ret = "unknown"; + + switch (type) { + case REDIS_REPLY_STRING: + ret = "string"; + break; + case REDIS_REPLY_ARRAY: + ret = "array"; + break; + case REDIS_REPLY_INTEGER: + ret = "int"; + break; + case REDIS_REPLY_STATUS: + ret = "status"; + break; + case REDIS_REPLY_NIL: + ret = "nil"; + break; + case REDIS_REPLY_ERROR: + ret = "error"; + break; + default: + break; + } + + return ret; +} diff --git a/src/libserver/redis_pool.h b/src/libserver/redis_pool.h index 5e5dc0b5d..a43b6d7e2 100644 --- a/src/libserver/redis_pool.h +++ b/src/libserver/redis_pool.h @@ -67,4 +67,11 @@ void rspamd_redis_pool_release_connection (struct rspamd_redis_pool *pool, */ void rspamd_redis_pool_destroy (struct rspamd_redis_pool *pool); +/** + * Missing in hiredis + * @param type + * @return + */ +const gchar* rspamd_redis_type_to_string (int type); + #endif /* SRC_LIBSERVER_REDIS_POOL_H_ */ diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c index e869f69ae..869ecad0f 100644 --- a/src/libstat/backends/redis_backend.c +++ b/src/libstat/backends/redis_backend.c @@ -767,8 +767,9 @@ rspamd_redis_connected (redisAsyncContext *c, gpointer r, gpointer priv) } else { if (reply->type != REDIS_REPLY_NIL) { - msg_err_task ("bad learned type for %s: %d", - rt->stcf->symbol, reply->type); + msg_err_task ("bad learned type for %s: %s, nil expected", + rt->stcf->symbol, + rspamd_redis_type_to_string (reply->type)); } val = 0; @@ -856,8 +857,8 @@ rspamd_redis_processed (redisAsyncContext *c, gpointer r, gpointer priv) } } else { - msg_err_task_check ("got invalid reply from redis: %d", - reply->type); + msg_err_task_check ("got invalid reply from redis: %s, array expected", + rspamd_redis_type_to_string (reply->type)); } msg_debug_task_check ("received tokens for %s: %d processed, %d found", -- 2.39.5