From b004051499ffd78cd4ca678e0a061cf279dedb6c Mon Sep 17 00:00:00 2001 From: michael-grunder Date: Thu, 14 Aug 2025 18:06:37 -0700 Subject: [PATCH] Rewowrk `CLUSTER_FREE_QUEUE` as a static function --- redis_cluster.c | 19 ++++++++++++++++--- redis_cluster.h | 10 ---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/redis_cluster.c b/redis_cluster.c index 1dcdf78..ea8a129 100644 --- a/redis_cluster.c +++ b/redis_cluster.c @@ -64,6 +64,19 @@ cluster_enqueue_response(redisCluster *c, short slot, cluster_cb cb, void *ctx) } } +static void cluster_free_queue(redisCluster *c) { + clusterFoldItem *item = c->multi_head, *tmp; + + while (item) { + tmp = item->next; + efree(item); + item = tmp; + } + + c->multi_head = NULL; + c->multi_curr = NULL; +} + void cluster_process_cmd(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, redis_cmd_cb cmd_cb, cluster_cb resp_cb, int readonly) @@ -2187,7 +2200,7 @@ PHP_METHOD(RedisCluster, exec) { CLUSTER_THROW_EXCEPTION("Error processing EXEC across the cluster", 0); // Free our queue, reset MULTI state - CLUSTER_FREE_QUEUE(c); + cluster_free_queue(c); CLUSTER_RESET_MULTI(c); RETURN_FALSE; @@ -2203,7 +2216,7 @@ PHP_METHOD(RedisCluster, exec) { // Free our callback queue, any enqueued distributed command context items // and reset our MULTI state. - CLUSTER_FREE_QUEUE(c); + cluster_free_queue(c); CLUSTER_RESET_MULTI(c); } @@ -2220,7 +2233,7 @@ PHP_METHOD(RedisCluster, discard) { CLUSTER_RESET_MULTI(c); } - CLUSTER_FREE_QUEUE(c); + cluster_free_queue(c); RETURN_TRUE; } diff --git a/redis_cluster.h b/redis_cluster.h index de0d55e..4dc833b 100644 --- a/redis_cluster.h +++ b/redis_cluster.h @@ -9,16 +9,6 @@ /* Get attached object context */ #define GET_CONTEXT() PHPREDIS_ZVAL_GET_OBJECT(redisCluster, getThis()) -/* Simple macro to free our enqueued callbacks after we EXEC */ -#define CLUSTER_FREE_QUEUE(c) \ - clusterFoldItem *_item = c->multi_head, *_tmp; \ - while(_item) { \ - _tmp = _item->next; \ - efree(_item); \ - _item = _tmp; \ - } \ - c->multi_head = c->multi_curr = NULL; \ - /* Reset anything flagged as MULTI */ #define CLUSTER_RESET_MULTI(c) \ redisClusterNode *_node; \