From d87f661f00cd65cdeba6e8aa20573543b3e180a8 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 27 Jun 2022 13:21:54 -0400 Subject: [PATCH] TT#182200 abstract Redis trash/backup table definitions Use a struct with globally defined instances instead of a literal string name to distinguish the two destination tables. This makes it possible to unify record handling between the two tables. Change-Id: I900debf3a28f262b4503d79562d69b69502b7aa8 --- medredis.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/medredis.c b/medredis.c index 544f901..9f78027 100644 --- a/medredis.c +++ b/medredis.c @@ -40,9 +40,16 @@ typedef struct { unsigned int append_counter; } medredis_con_t; +typedef struct { + const char *name; +} medredis_table_t; + static medredis_con_t *con = NULL; static char medredis_srem_key_lua[41]; // sha-1 hex string +static medredis_table_t medredis_table_trash = { .name = "trash" }; +static medredis_table_t medredis_table_backup = { .name = "backup" }; + /**********************************************************************/ static void medredis_free_reply(redisReply **reply) { if (reply && *reply) { @@ -802,10 +809,10 @@ err: } /**********************************************************************/ -static int medredis_cleanup_entries(GQueue *records, const char *table) { +static int medredis_cleanup_entries(GQueue *records, medredis_table_t *table) { char buffer[512]; - if (medmysql_insert_records(records, table) != 0) { + if (medmysql_insert_records(records, table->name) != 0) { L_CRITICAL("Failed to cleanup redis records\n"); goto err; } @@ -854,10 +861,10 @@ err: /**********************************************************************/ int medredis_trash_entries(GQueue *records) { - return medredis_cleanup_entries(records, "trash"); + return medredis_cleanup_entries(records, &medredis_table_trash); } /**********************************************************************/ int medredis_backup_entries(GQueue *records) { - return medredis_cleanup_entries(records, "backup"); + return medredis_cleanup_entries(records, &medredis_table_backup); }