]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add routine to convert redis reply type to string
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 17 Feb 2017 13:25:25 +0000 (13:25 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 17 Feb 2017 13:25:25 +0000 (13:25 +0000)
Issue: #1228

src/libserver/redis_pool.c
src/libserver/redis_pool.h
src/libstat/backends/redis_backend.c

index 5cb8986486d6b294446442d2aa3842e3e3d89a27..0b7c308444778d70044bcabe9d66a51fb599ab46 100644 (file)
@@ -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;
+}
index 5e5dc0b5d67d9d4be4de73d4ec78f8b39a85f9c5..a43b6d7e263b47b631728c76cf87bdefa9ec9332 100644 (file)
@@ -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_ */
index e869f69ae4a2bffc63f90450ad50a90530dce79c..869ecad0ff880d4c49c99684da2f447c91c69cd6 100644 (file)
@@ -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",