diff --git a/include/valkey/valkeycluster.h b/include/valkey/valkeycluster.h index 3f38034..9300551 100644 --- a/include/valkey/valkeycluster.h +++ b/include/valkey/valkeycluster.h @@ -259,9 +259,10 @@ void valkeyClusterReset(valkeyClusterContext *cc); /* Update the slotmap by querying any node. */ int valkeyClusterUpdateSlotmap(valkeyClusterContext *cc); -/* Internal functions */ -valkeyContext *ctx_get_by_node(valkeyClusterContext *cc, - valkeyClusterNode *node); +/* Get the valkeyContext used for communication with a given node. + * Connects or reconnects to the node if necessary. */ +valkeyContext *valkeyClusterGetValkeyContext(valkeyClusterContext *cc, + valkeyClusterNode *node); /* * Asynchronous API @@ -316,9 +317,10 @@ int valkeyClusterAsyncFormattedCommandToNode(valkeyClusterAsyncContext *acc, void *privdata, char *cmd, int len); -/* Internal functions */ -valkeyAsyncContext *actx_get_by_node(valkeyClusterAsyncContext *acc, - valkeyClusterNode *node); +/* Get the valkeyAsyncContext used for communication with a given node. + * Connects or reconnects to the node if necessary. */ +valkeyAsyncContext *valkeyClusterGetValkeyAsyncContext(valkeyClusterAsyncContext *acc, + valkeyClusterNode *node); /* Cluster node iterator functions */ void valkeyClusterInitNodeIterator(valkeyClusterNodeIterator *iter, diff --git a/src/valkeycluster.c b/src/valkeycluster.c index c0a3542..42062cf 100644 --- a/src/valkeycluster.c +++ b/src/valkeycluster.c @@ -1788,8 +1788,8 @@ int valkeyClusterConnect2(valkeyClusterContext *cc) { return valkeyClusterUpdateSlotmap(cc); } -valkeyContext *ctx_get_by_node(valkeyClusterContext *cc, - valkeyClusterNode *node) { +valkeyContext *valkeyClusterGetValkeyContext(valkeyClusterContext *cc, + valkeyClusterNode *node) { valkeyContext *c = NULL; if (node == NULL) { return NULL; @@ -1901,7 +1901,7 @@ static int valkeyClusterAppendCommandInternal(valkeyClusterContext *cc, return VALKEY_ERR; } - c = ctx_get_by_node(cc, node); + c = valkeyClusterGetValkeyContext(cc, node); if (c == NULL) { return VALKEY_ERR; } else if (c->err) { @@ -2066,7 +2066,7 @@ static void *valkey_cluster_command_execute(valkeyClusterContext *cc, } } - c = ctx_get_by_node(cc, node); + c = valkeyClusterGetValkeyContext(cc, node); if (c == NULL || c->err) { /* Failed to connect. Maybe there was a failover and this node is gone. * Update slotmap to find out. */ @@ -2078,7 +2078,7 @@ static void *valkey_cluster_command_execute(valkeyClusterContext *cc, if (node == NULL) { goto error; } - c = ctx_get_by_node(cc, node); + c = valkeyClusterGetValkeyContext(cc, node); if (c == NULL) { goto error; } else if (c->err) { @@ -2154,7 +2154,7 @@ static void *valkey_cluster_command_execute(valkeyClusterContext *cc, } } - c = ctx_get_by_node(cc, node); + c = valkeyClusterGetValkeyContext(cc, node); if (c == NULL) { goto error; } else if (c->err) { @@ -2174,7 +2174,7 @@ static void *valkey_cluster_command_execute(valkeyClusterContext *cc, freeReplyObject(reply); reply = NULL; - c = ctx_get_by_node(cc, node); + c = valkeyClusterGetValkeyContext(cc, node); if (c == NULL) { goto error; } else if (c->err) { @@ -2371,7 +2371,7 @@ void *valkeyClustervCommandToNode(valkeyClusterContext *cc, void *reply; int updating_slotmap = 0; - c = ctx_get_by_node(cc, node); + c = valkeyClusterGetValkeyContext(cc, node); if (c == NULL) { return NULL; } else if (c->err) { @@ -2550,7 +2550,7 @@ int valkeyClustervAppendCommandToNode(valkeyClusterContext *cc, cc->requests->free = listCommandFree; } - c = ctx_get_by_node(cc, node); + c = valkeyClusterGetValkeyContext(cc, node); if (c == NULL) { return VALKEY_ERR; } else if (c->err) { @@ -2653,7 +2653,7 @@ static int valkeyClusterSendAll(valkeyClusterContext *cc) { continue; } - c = ctx_get_by_node(cc, node); + c = valkeyClusterGetValkeyContext(cc, node); if (c == NULL) { continue; } @@ -2880,8 +2880,9 @@ static void unlinkAsyncContextAndNode(void *data) { } } -valkeyAsyncContext *actx_get_by_node(valkeyClusterAsyncContext *acc, - valkeyClusterNode *node) { +valkeyAsyncContext * +valkeyClusterGetValkeyAsyncContext(valkeyClusterAsyncContext *acc, + valkeyClusterNode *node) { valkeyAsyncContext *ac; int ret; @@ -3168,7 +3169,7 @@ static int updateSlotMapAsync(valkeyClusterAsyncContext *acc, } /* Get libvalkey context, connect if needed */ - ac = actx_get_by_node(acc, node); + ac = valkeyClusterGetValkeyAsyncContext(acc, node); } if (ac == NULL) goto error; /* Specific error already set */ @@ -3277,7 +3278,7 @@ static void valkeyClusterAsyncCallback(valkeyAsyncContext *ac, void *r, if (slot >= 0) { cc->table[slot] = node; } - ac_retry = actx_get_by_node(acc, node); + ac_retry = valkeyClusterGetValkeyAsyncContext(acc, node); break; case CLUSTER_ERR_ASK: @@ -3287,7 +3288,7 @@ static void valkeyClusterAsyncCallback(valkeyAsyncContext *ac, void *r, goto done; } - ac_retry = actx_get_by_node(acc, node); + ac_retry = valkeyClusterGetValkeyAsyncContext(acc, node); if (ac_retry == NULL) { /* Specific error already set */ goto done; @@ -3411,7 +3412,7 @@ int valkeyClusterAsyncFormattedCommand(valkeyClusterAsyncContext *acc, goto error; } - ac = actx_get_by_node(acc, node); + ac = valkeyClusterGetValkeyAsyncContext(acc, node); if (ac == NULL) { /* Specific error already set */ goto error; @@ -3463,7 +3464,7 @@ int valkeyClusterAsyncFormattedCommandToNode(valkeyClusterAsyncContext *acc, return VALKEY_ERR; } - ac = actx_get_by_node(acc, node); + ac = valkeyClusterGetValkeyAsyncContext(acc, node); if (ac == NULL) { /* Specific error already set */ return VALKEY_ERR;