From ccdb606e70f6026e47366eec4c952c2622cf07bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Thu, 30 May 2024 00:03:30 +0200 Subject: [PATCH 1/6] Rename files in libvalkeycluster MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Svensson --- .../tests/scripts/{simulated-redis.pl => simulated-valkey.pl} | 0 ...edis_cluster-config.cmake.in => valkeycluster-config.cmake.in} | 0 libvalkeycluster/{hircluster.c => valkeycluster.c} | 0 libvalkeycluster/{hircluster.h => valkeycluster.h} | 0 libvalkeycluster/{hiredis_cluster.pc.in => valkeycluster.pc.in} | 0 ...ster_ssl-config.cmake.in => valkeycluster_ssl-config.cmake.in} | 0 libvalkeycluster/{hircluster_ssl.c => valkeycluster_ssl.c} | 0 libvalkeycluster/{hircluster_ssl.h => valkeycluster_ssl.h} | 0 .../{hiredis_cluster_ssl.pc.in => valkeycluster_ssl.pc.in} | 0 libvalkeycluster/{hiarray.c => vkarray.c} | 0 libvalkeycluster/{hiarray.h => vkarray.h} | 0 libvalkeycluster/{hiutil.c => vkutil.c} | 0 libvalkeycluster/{hiutil.h => vkutil.h} | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename libvalkeycluster/tests/scripts/{simulated-redis.pl => simulated-valkey.pl} (100%) rename libvalkeycluster/{hiredis_cluster-config.cmake.in => valkeycluster-config.cmake.in} (100%) rename libvalkeycluster/{hircluster.c => valkeycluster.c} (100%) rename libvalkeycluster/{hircluster.h => valkeycluster.h} (100%) rename libvalkeycluster/{hiredis_cluster.pc.in => valkeycluster.pc.in} (100%) rename libvalkeycluster/{hiredis_cluster_ssl-config.cmake.in => valkeycluster_ssl-config.cmake.in} (100%) rename libvalkeycluster/{hircluster_ssl.c => valkeycluster_ssl.c} (100%) rename libvalkeycluster/{hircluster_ssl.h => valkeycluster_ssl.h} (100%) rename libvalkeycluster/{hiredis_cluster_ssl.pc.in => valkeycluster_ssl.pc.in} (100%) rename libvalkeycluster/{hiarray.c => vkarray.c} (100%) rename libvalkeycluster/{hiarray.h => vkarray.h} (100%) rename libvalkeycluster/{hiutil.c => vkutil.c} (100%) rename libvalkeycluster/{hiutil.h => vkutil.h} (100%) diff --git a/libvalkeycluster/tests/scripts/simulated-redis.pl b/libvalkeycluster/tests/scripts/simulated-valkey.pl similarity index 100% rename from libvalkeycluster/tests/scripts/simulated-redis.pl rename to libvalkeycluster/tests/scripts/simulated-valkey.pl diff --git a/libvalkeycluster/hiredis_cluster-config.cmake.in b/libvalkeycluster/valkeycluster-config.cmake.in similarity index 100% rename from libvalkeycluster/hiredis_cluster-config.cmake.in rename to libvalkeycluster/valkeycluster-config.cmake.in diff --git a/libvalkeycluster/hircluster.c b/libvalkeycluster/valkeycluster.c similarity index 100% rename from libvalkeycluster/hircluster.c rename to libvalkeycluster/valkeycluster.c diff --git a/libvalkeycluster/hircluster.h b/libvalkeycluster/valkeycluster.h similarity index 100% rename from libvalkeycluster/hircluster.h rename to libvalkeycluster/valkeycluster.h diff --git a/libvalkeycluster/hiredis_cluster.pc.in b/libvalkeycluster/valkeycluster.pc.in similarity index 100% rename from libvalkeycluster/hiredis_cluster.pc.in rename to libvalkeycluster/valkeycluster.pc.in diff --git a/libvalkeycluster/hiredis_cluster_ssl-config.cmake.in b/libvalkeycluster/valkeycluster_ssl-config.cmake.in similarity index 100% rename from libvalkeycluster/hiredis_cluster_ssl-config.cmake.in rename to libvalkeycluster/valkeycluster_ssl-config.cmake.in diff --git a/libvalkeycluster/hircluster_ssl.c b/libvalkeycluster/valkeycluster_ssl.c similarity index 100% rename from libvalkeycluster/hircluster_ssl.c rename to libvalkeycluster/valkeycluster_ssl.c diff --git a/libvalkeycluster/hircluster_ssl.h b/libvalkeycluster/valkeycluster_ssl.h similarity index 100% rename from libvalkeycluster/hircluster_ssl.h rename to libvalkeycluster/valkeycluster_ssl.h diff --git a/libvalkeycluster/hiredis_cluster_ssl.pc.in b/libvalkeycluster/valkeycluster_ssl.pc.in similarity index 100% rename from libvalkeycluster/hiredis_cluster_ssl.pc.in rename to libvalkeycluster/valkeycluster_ssl.pc.in diff --git a/libvalkeycluster/hiarray.c b/libvalkeycluster/vkarray.c similarity index 100% rename from libvalkeycluster/hiarray.c rename to libvalkeycluster/vkarray.c diff --git a/libvalkeycluster/hiarray.h b/libvalkeycluster/vkarray.h similarity index 100% rename from libvalkeycluster/hiarray.h rename to libvalkeycluster/vkarray.h diff --git a/libvalkeycluster/hiutil.c b/libvalkeycluster/vkutil.c similarity index 100% rename from libvalkeycluster/hiutil.c rename to libvalkeycluster/vkutil.c diff --git a/libvalkeycluster/hiutil.h b/libvalkeycluster/vkutil.h similarity index 100% rename from libvalkeycluster/hiutil.h rename to libvalkeycluster/vkutil.h From 49522e38256bdf6abf27009d635abf8829aaeac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Thu, 30 May 2024 01:04:51 +0200 Subject: [PATCH 2/6] Initial renaming of hiredis-cluster code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Svensson --- libvalkeycluster/adapters/ae.h | 22 +- libvalkeycluster/adapters/glib.h | 32 +- libvalkeycluster/adapters/libev.h | 20 +- libvalkeycluster/adapters/libevent.h | 20 +- libvalkeycluster/adapters/libuv.h | 20 +- libvalkeycluster/adlist.c | 22 +- libvalkeycluster/command.c | 114 +- libvalkeycluster/command.h | 22 +- libvalkeycluster/crc16.c | 2 +- libvalkeycluster/dict.c | 16 +- .../examples/src/clientside_caching_async.c | 124 +- libvalkeycluster/examples/src/example.c | 20 +- libvalkeycluster/examples/src/example_async.c | 50 +- libvalkeycluster/examples/src/example_tls.c | 42 +- libvalkeycluster/gencommands.py | 28 +- libvalkeycluster/tests/clusterclient.c | 52 +- libvalkeycluster/tests/clusterclient_async.c | 74 +- .../tests/clusterclient_reconnect_async.c | 54 +- libvalkeycluster/tests/ct_async.c | 91 +- libvalkeycluster/tests/ct_async_glib.c | 44 +- libvalkeycluster/tests/ct_async_libev.c | 42 +- libvalkeycluster/tests/ct_async_libuv.c | 42 +- libvalkeycluster/tests/ct_commands.c | 296 +-- libvalkeycluster/tests/ct_connection.c | 452 ++--- libvalkeycluster/tests/ct_connection_ipv6.c | 28 +- .../tests/ct_out_of_memory_handling.c | 318 ++- libvalkeycluster/tests/ct_pipeline.c | 140 +- libvalkeycluster/tests/ct_specific_nodes.c | 378 ++-- libvalkeycluster/tests/main_async_tls.c | 64 +- libvalkeycluster/tests/main_tls.c | 38 +- .../ask-redirect-connection-error-test.sh | 17 +- .../tests/scripts/ask-redirect-test.sh | 8 +- .../ask-redirect-using-cluster-nodes-test.sh | 8 +- .../tests/scripts/cluster-down-test.sh | 8 +- .../tests/scripts/cluster-scale-down-test.sh | 8 +- .../scripts/command-from-callback-test.sh | 12 +- .../connect-error-using-cluster-nodes-test.sh | 4 +- .../tests/scripts/connection-error-test.sh | 20 +- ...o-all-nodes-during-scaledown-test-async.sh | 8 +- ...size-to-all-nodes-during-scaledown-test.sh | 8 +- .../tests/scripts/dbsize-to-all-nodes-test.sh | 8 +- .../tests/scripts/moved-redirect-test.sh | 8 +- ...moved-redirect-using-cluster-nodes-test.sh | 8 +- .../tests/scripts/reconnect-test.sh | 2 +- .../scripts/redirect-with-hostname-test.sh | 14 +- .../tests/scripts/redirect-with-ipv6-test.sh | 8 +- libvalkeycluster/tests/scripts/redis-cluster | 21 +- .../tests/scripts/set-get-test.sh | 2 +- .../tests/scripts/simulated-valkey.pl | 14 +- .../scripts/slots-not-served-test-async.sh | 4 +- .../tests/scripts/slots-not-served-test.sh | 4 +- .../tests/scripts/timeout-handling-test.sh | 22 +- libvalkeycluster/tests/test_utils.c | 48 +- libvalkeycluster/tests/test_utils.h | 18 +- libvalkeycluster/tests/ut_parse_cmd.c | 114 +- libvalkeycluster/valkeycluster.c | 1808 ++++++++--------- libvalkeycluster/valkeycluster.h | 287 ++- libvalkeycluster/valkeycluster_ssl.c | 18 +- libvalkeycluster/valkeycluster_ssl.h | 8 +- libvalkeycluster/vkarray.c | 58 +- libvalkeycluster/vkarray.h | 40 +- libvalkeycluster/vkutil.c | 54 +- libvalkeycluster/vkutil.h | 104 +- 63 files changed, 2673 insertions(+), 2767 deletions(-) diff --git a/libvalkeycluster/adapters/ae.h b/libvalkeycluster/adapters/ae.h index 9314c2b7..ed26162d 100644 --- a/libvalkeycluster/adapters/ae.h +++ b/libvalkeycluster/adapters/ae.h @@ -28,27 +28,27 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __HIREDIS_CLUSTER_AE_H__ -#define __HIREDIS_CLUSTER_AE_H__ +#ifndef __VALKEYCLUSTER_AE_H__ +#define __VALKEYCLUSTER_AE_H__ -#include "../hircluster.h" -#include +#include "../valkeycluster.h" +#include -static int redisAeAttach_link(redisAsyncContext *ac, void *base) { - return redisAeAttach((aeEventLoop *)base, ac); +static int valkeyAeAttach_link(valkeyAsyncContext *ac, void *base) { + return valkeyAeAttach((aeEventLoop *)base, ac); } -static int redisClusterAeAttach(aeEventLoop *loop, - redisClusterAsyncContext *acc) { +static int valkeyClusterAeAttach(aeEventLoop *loop, + valkeyClusterAsyncContext *acc) { if (acc == NULL || loop == NULL) { - return REDIS_ERR; + return VALKEY_ERR; } acc->adapter = loop; - acc->attach_fn = redisAeAttach_link; + acc->attach_fn = valkeyAeAttach_link; - return REDIS_OK; + return VALKEY_OK; } #endif diff --git a/libvalkeycluster/adapters/glib.h b/libvalkeycluster/adapters/glib.h index c3718a21..5cd2749f 100644 --- a/libvalkeycluster/adapters/glib.h +++ b/libvalkeycluster/adapters/glib.h @@ -28,34 +28,34 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __HIREDIS_CLUSTER_GLIB_H__ -#define __HIREDIS_CLUSTER_GLIB_H__ +#ifndef __VALKEYCLUSTER_GLIB_H__ +#define __VALKEYCLUSTER_GLIB_H__ -#include "../hircluster.h" -#include +#include "../valkeycluster.h" +#include -typedef struct redisClusterGlibAdapter { +typedef struct valkeyClusterGlibAdapter { GMainContext *context; -} redisClusterGlibAdapter; +} valkeyClusterGlibAdapter; -static int redisGlibAttach_link(redisAsyncContext *ac, void *adapter) { - GMainContext *context = ((redisClusterGlibAdapter *)adapter)->context; - if (g_source_attach(redis_source_new(ac), context) > 0) { - return REDIS_OK; +static int valkeyGlibAttach_link(valkeyAsyncContext *ac, void *adapter) { + GMainContext *context = ((valkeyClusterGlibAdapter *)adapter)->context; + if (g_source_attach(valkey_source_new(ac), context) > 0) { + return VALKEY_OK; } - return REDIS_ERR; + return VALKEY_ERR; } -static int redisClusterGlibAttach(redisClusterAsyncContext *acc, - redisClusterGlibAdapter *adapter) { +static int valkeyClusterGlibAttach(valkeyClusterAsyncContext *acc, + valkeyClusterGlibAdapter *adapter) { if (acc == NULL || adapter == NULL) { - return REDIS_ERR; + return VALKEY_ERR; } acc->adapter = adapter; - acc->attach_fn = redisGlibAttach_link; + acc->attach_fn = valkeyGlibAttach_link; - return REDIS_OK; + return VALKEY_OK; } #endif diff --git a/libvalkeycluster/adapters/libev.h b/libvalkeycluster/adapters/libev.h index 084fd34f..54b95afd 100644 --- a/libvalkeycluster/adapters/libev.h +++ b/libvalkeycluster/adapters/libev.h @@ -28,26 +28,26 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __HIREDIS_CLUSTER_LIBEV_H__ -#define __HIREDIS_CLUSTER_LIBEV_H__ +#ifndef __LIBVALKEYCLUSTER_LIBEV_H__ +#define __LIBVALKEYCLUSTER_LIBEV_H__ -#include "../hircluster.h" -#include +#include "../valkeycluster.h" +#include -static int redisLibevAttach_link(redisAsyncContext *ac, void *loop) { - return redisLibevAttach((struct ev_loop *)loop, ac); +static int valkeyLibevAttach_link(valkeyAsyncContext *ac, void *loop) { + return valkeyLibevAttach((struct ev_loop *)loop, ac); } -static int redisClusterLibevAttach(redisClusterAsyncContext *acc, +static int valkeyClusterLibevAttach(valkeyClusterAsyncContext *acc, struct ev_loop *loop) { if (loop == NULL || acc == NULL) { - return REDIS_ERR; + return VALKEY_ERR; } acc->adapter = loop; - acc->attach_fn = redisLibevAttach_link; + acc->attach_fn = valkeyLibevAttach_link; - return REDIS_OK; + return VALKEY_OK; } #endif diff --git a/libvalkeycluster/adapters/libevent.h b/libvalkeycluster/adapters/libevent.h index 87d312f0..ff5604d7 100644 --- a/libvalkeycluster/adapters/libevent.h +++ b/libvalkeycluster/adapters/libevent.h @@ -28,27 +28,27 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __HIREDIS_CLUSTER_LIBEVENT_H__ -#define __HIREDIS_CLUSTER_LIBEVENT_H__ +#ifndef __LIBVALKEYCLUSTER_LIBEVENT_H__ +#define __LIBVALKEYCLUSTER_LIBEVENT_H__ -#include "../hircluster.h" -#include +#include "../valkeycluster.h" +#include -static int redisLibeventAttach_link(redisAsyncContext *ac, void *base) { - return redisLibeventAttach(ac, (struct event_base *)base); +static int valkeyLibeventAttach_link(valkeyAsyncContext *ac, void *base) { + return valkeyLibeventAttach(ac, (struct event_base *)base); } -static int redisClusterLibeventAttach(redisClusterAsyncContext *acc, +static int valkeyClusterLibeventAttach(valkeyClusterAsyncContext *acc, struct event_base *base) { if (acc == NULL || base == NULL) { - return REDIS_ERR; + return VALKEY_ERR; } acc->adapter = base; - acc->attach_fn = redisLibeventAttach_link; + acc->attach_fn = valkeyLibeventAttach_link; - return REDIS_OK; + return VALKEY_OK; } #endif diff --git a/libvalkeycluster/adapters/libuv.h b/libvalkeycluster/adapters/libuv.h index 527419e2..9f59769a 100644 --- a/libvalkeycluster/adapters/libuv.h +++ b/libvalkeycluster/adapters/libuv.h @@ -28,27 +28,27 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __HIREDIS_CLUSTER_LIBUV_H__ -#define __HIREDIS_CLUSTER_LIBUV_H__ +#ifndef __LIBVALKEYCLUSTER_LIBUV_H__ +#define __LIBVALKEYCLUSTER_LIBUV_H__ -#include "../hircluster.h" -#include +#include "../valkeycluster.h" +#include -static int redisLibuvAttach_link(redisAsyncContext *ac, void *loop) { - return redisLibuvAttach(ac, (uv_loop_t *)loop); +static int valkeyLibuvAttach_link(valkeyAsyncContext *ac, void *loop) { + return valkeyLibuvAttach(ac, (uv_loop_t *)loop); } -static int redisClusterLibuvAttach(redisClusterAsyncContext *acc, +static int valkeyClusterLibuvAttach(valkeyClusterAsyncContext *acc, uv_loop_t *loop) { if (acc == NULL || loop == NULL) { - return REDIS_ERR; + return VALKEY_ERR; } acc->adapter = loop; - acc->attach_fn = redisLibuvAttach_link; + acc->attach_fn = valkeyLibuvAttach_link; - return REDIS_OK; + return VALKEY_OK; } #endif diff --git a/libvalkeycluster/adlist.c b/libvalkeycluster/adlist.c index 18b04d44..50e5243f 100644 --- a/libvalkeycluster/adlist.c +++ b/libvalkeycluster/adlist.c @@ -27,11 +27,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include "adlist.h" -#include "hiutil.h" +#include "vkutil.h" /* Create a new list. The created list can be freed with * AlFreeList(), but private value of every node need to be freed @@ -41,7 +41,7 @@ hilist *listCreate(void) { struct hilist *list; - if ((list = hi_malloc(sizeof(*list))) == NULL) + if ((list = vk_malloc(sizeof(*list))) == NULL) return NULL; list->head = list->tail = NULL; list->len = 0; @@ -64,10 +64,10 @@ void listRelease(hilist *list) { next = current->next; if (list->free) list->free(current->value); - hi_free(current); + vk_free(current); current = next; } - hi_free(list); + vk_free(list); } /* Add a new node to the list, to head, containing the specified 'value' @@ -79,7 +79,7 @@ void listRelease(hilist *list) { hilist *listAddNodeHead(hilist *list, void *value) { listNode *node; - if ((node = hi_malloc(sizeof(*node))) == NULL) + if ((node = vk_malloc(sizeof(*node))) == NULL) return NULL; node->value = value; if (list->len == 0) { @@ -104,7 +104,7 @@ hilist *listAddNodeHead(hilist *list, void *value) { hilist *listAddNodeTail(hilist *list, void *value) { listNode *node; - if ((node = hi_malloc(sizeof(*node))) == NULL) + if ((node = vk_malloc(sizeof(*node))) == NULL) return NULL; node->value = value; if (list->len == 0) { @@ -124,7 +124,7 @@ hilist *listInsertNode(hilist *list, listNode *old_node, void *value, int after) { listNode *node; - if ((node = hi_malloc(sizeof(*node))) == NULL) + if ((node = vk_malloc(sizeof(*node))) == NULL) return NULL; node->value = value; if (after) { @@ -165,7 +165,7 @@ void listDelNode(hilist *list, listNode *node) { list->tail = node->prev; if (list->free) list->free(node->value); - hi_free(node); + vk_free(node); list->len--; } @@ -176,7 +176,7 @@ void listDelNode(hilist *list, listNode *node) { listIter *listGetIterator(hilist *list, int direction) { listIter *iter; - if ((iter = hi_malloc(sizeof(*iter))) == NULL) + if ((iter = vk_malloc(sizeof(*iter))) == NULL) return NULL; if (direction == AL_START_HEAD) iter->next = list->head; @@ -187,7 +187,7 @@ listIter *listGetIterator(hilist *list, int direction) { } /* Release the iterator memory */ -void listReleaseIterator(listIter *iter) { hi_free(iter); } +void listReleaseIterator(listIter *iter) { vk_free(iter); } /* Create an iterator in the list private iterator structure */ void listRewind(hilist *list, listIter *li) { diff --git a/libvalkeycluster/command.c b/libvalkeycluster/command.c index 30fc7ca5..07718336 100644 --- a/libvalkeycluster/command.c +++ b/libvalkeycluster/command.c @@ -30,7 +30,7 @@ */ #include #include -#include +#include #ifndef _WIN32 #include #include @@ -40,8 +40,8 @@ #include #include "command.h" -#include "hiarray.h" -#include "hiutil.h" +#include "vkarray.h" +#include "vkutil.h" #include "win32.h" #define LF (uint8_t)10 @@ -65,10 +65,10 @@ typedef struct { int8_t arity; /* Arity, neg number means min num args */ } cmddef; -/* Populate the table with code in cmddef.h generated from Redis JSON files. */ -static cmddef redis_commands[] = { +/* Populate the table with code in cmddef.h generated from Valkey JSON files. */ +static cmddef valkey_commands[] = { #define COMMAND(_type, _name, _subname, _arity, _keymethod, _keypos) \ - {.type = CMD_REQ_REDIS_##_type, \ + {.type = CMD_REQ_VALKEY_##_type, \ .name = _name, \ .subname = _subname, \ .firstkeymethod = KEYPOS_##_keymethod, \ @@ -92,9 +92,9 @@ static inline void to_upper(char *dst, const char *src, uint32_t len) { * to lookup the command. The function returns CMD_UNKNOWN on failure. On * success, the command type is returned and *firstkey and *arity are * populated. */ -cmddef *redis_lookup_cmd(const char *arg0, uint32_t arg0_len, const char *arg1, - uint32_t arg1_len) { - int num_commands = sizeof(redis_commands) / sizeof(cmddef); +cmddef *valkey_lookup_cmd(const char *arg0, uint32_t arg0_len, const char *arg1, + uint32_t arg1_len) { + int num_commands = sizeof(valkey_commands) / sizeof(cmddef); /* Compare command name in uppercase. */ char *cmd = alloca(arg0_len); to_upper(cmd, arg0, arg0_len); @@ -103,7 +103,7 @@ cmddef *redis_lookup_cmd(const char *arg0, uint32_t arg0_len, const char *arg1, int left = 0, right = num_commands - 1; while (left <= right) { int i = (left + right) / 2; - cmddef *c = &redis_commands[i]; + cmddef *c = &valkey_commands[i]; int cmp = strncmp(c->name, cmd, arg0_len); if (cmp == 0 && strlen(c->name) > arg0_len) @@ -137,15 +137,15 @@ cmddef *redis_lookup_cmd(const char *arg0, uint32_t arg0_len, const char *arg1, } /* - * Return true, if the redis command is a vector command accepting one or + * Return true, if the valkey command is a vector command accepting one or * more keys, otherwise return false * Format: command key [ key ... ] */ -static int redis_argx(struct cmd *r) { +static int valkey_argx(struct cmd *r) { switch (r->type) { - case CMD_REQ_REDIS_EXISTS: - case CMD_REQ_REDIS_MGET: - case CMD_REQ_REDIS_DEL: + case CMD_REQ_VALKEY_EXISTS: + case CMD_REQ_VALKEY_MGET: + case CMD_REQ_VALKEY_DEL: return 1; default: @@ -156,13 +156,13 @@ static int redis_argx(struct cmd *r) { } /* - * Return true, if the redis command is a vector command accepting one or + * Return true, if the valkey command is a vector command accepting one or * more key-value pairs, otherwise return false * Format: command key value [ key value ... ] */ -static int redis_argkvx(struct cmd *r) { +static int valkey_argkvx(struct cmd *r) { switch (r->type) { - case CMD_REQ_REDIS_MSET: + case CMD_REQ_VALKEY_MSET: return 1; default: @@ -176,7 +176,7 @@ static int redis_argkvx(struct cmd *r) { * Returns the remaining of the input after consuming the bulk string. The * pointers *str and *len are pointed to the parsed string and its length. On * parse error, NULL is returned. */ -char *redis_parse_bulk(char *p, char *end, char **str, uint32_t *len) { +char *valkey_parse_bulk(char *p, char *end, char **str, uint32_t *len) { uint32_t length = 0; if (p >= end || *p++ != '$') return NULL; @@ -200,7 +200,7 @@ char *redis_parse_bulk(char *p, char *end, char **str, uint32_t *len) { } static inline int push_keypos(struct cmd *r, char *arg, uint32_t arglen) { - struct keypos *kpos = hiarray_push(r->keys); + struct keypos *kpos = vkarray_push(r->keys); if (kpos == NULL) return 0; kpos->start = arg; @@ -208,31 +208,7 @@ static inline int push_keypos(struct cmd *r, char *arg, uint32_t arglen) { return 1; } -/* - * Reference: http://redis.io/topics/protocol - * - * Redis >= 1.2 uses the unified protocol to send requests to the Redis - * server. In the unified protocol all the arguments sent to the server - * are binary safe and every request has the following general form: - * - * * CR LF - * $ CR LF - * CR LF - * ... - * $ CR LF - * CR LF - * - * Before the unified request protocol, redis protocol for requests supported - * the following commands - * 1). Inline commands: simple commands where arguments are just space - * separated strings. No binary safeness is possible. - * 2). Bulk commands: bulk commands are exactly like inline commands, but - * the last argument is handled in a special way in order to allow for - * a binary-safe last argument. - * - * only supports the Redis unified protocol for requests. - */ -void redis_parse_cmd(struct cmd *r) { +void valkey_parse_cmd(struct cmd *r) { ASSERT(r->cmd != NULL && r->clen > 0); char *p = r->cmd; char *end = r->cmd + r->clen; @@ -261,17 +237,17 @@ void redis_parse_cmd(struct cmd *r) { r->narg = rnarg; /* Parse the first two args. */ - if ((p = redis_parse_bulk(p, end, &arg0, &arg0_len)) == NULL) + if ((p = valkey_parse_bulk(p, end, &arg0, &arg0_len)) == NULL) goto error; argidx++; if (rnarg > 1) { - if ((p = redis_parse_bulk(p, end, &arg1, &arg1_len)) == NULL) + if ((p = valkey_parse_bulk(p, end, &arg1, &arg1_len)) == NULL) goto error; argidx++; } /* Lookup command. */ - if ((info = redis_lookup_cmd(arg0, arg0_len, arg1, arg1_len)) == NULL) + if ((info = valkey_lookup_cmd(arg0, arg0_len, arg1, arg1_len)) == NULL) goto error; /* Command not found. */ r->type = info->type; @@ -292,14 +268,14 @@ void redis_parse_cmd(struct cmd *r) { /* Keyword-based first key position */ const char *keyword; int startfrom; - if (r->type == CMD_REQ_REDIS_XREAD) { + if (r->type == CMD_REQ_VALKEY_XREAD) { keyword = "STREAMS"; startfrom = 1; - } else if (r->type == CMD_REQ_REDIS_XREADGROUP) { + } else if (r->type == CMD_REQ_VALKEY_XREADGROUP) { keyword = "STREAMS"; startfrom = 4; } else { - /* Not reached, but can be reached if Redis adds more commands. */ + /* Not reached, but can be reached if Valkey adds more commands. */ goto error; } @@ -307,13 +283,13 @@ void redis_parse_cmd(struct cmd *r) { arg = arg1; arglen = arg1_len; while (argidx < (int)rnarg - 1) { - if ((p = redis_parse_bulk(p, end, &arg, &arglen)) == NULL) + if ((p = valkey_parse_bulk(p, end, &arg, &arglen)) == NULL) goto error; /* Keyword not provided, thus no keys. */ if (argidx++ < startfrom) continue; /* Keyword can't appear in a position before 'startfrom' */ if (!strncasecmp(keyword, arg, arglen)) { /* Keyword found. Now the first key is the next arg. */ - if ((p = redis_parse_bulk(p, end, &arg, &arglen)) == NULL) + if ((p = valkey_parse_bulk(p, end, &arg, &arglen)) == NULL) goto error; if (!push_keypos(r, arg, arglen)) goto oom; @@ -329,7 +305,7 @@ void redis_parse_cmd(struct cmd *r) { arg = arg1; arglen = arg1_len; for (; argidx < info->firstkeypos; argidx++) { - if ((p = redis_parse_bulk(p, end, &arg, &arglen)) == NULL) + if ((p = valkey_parse_bulk(p, end, &arg, &arglen)) == NULL) goto error; } @@ -341,14 +317,14 @@ void redis_parse_cmd(struct cmd *r) { if (!strncmp("0", arg, arglen)) goto done; /* No args. */ /* One or more args. The first key is the arg after the 'numkeys' arg. */ - if ((p = redis_parse_bulk(p, end, &arg, &arglen)) == NULL) + if ((p = valkey_parse_bulk(p, end, &arg, &arglen)) == NULL) goto error; argidx++; } /* Now arg is the first key and arglen is its length. */ - if (info->type == CMD_REQ_REDIS_MIGRATE && arglen == 0 && + if (info->type == CMD_REQ_VALKEY_MIGRATE && arglen == 0 && info->firstkeymethod == KEYPOS_INDEX && info->firstkeypos == 3) { /* MIGRATE host port destination-db timeout [COPY] [REPLACE] * [[AUTH password] | [AUTH2 username password]] [KEYS key [key ...]] @@ -363,15 +339,15 @@ void redis_parse_cmd(struct cmd *r) { goto oom; /* Special commands where we want all keys (not only the first key). */ - if (redis_argx(r) || redis_argkvx(r)) { + if (valkey_argx(r) || valkey_argkvx(r)) { /* argx: MGET key [ key ... ] */ /* argkvx: MSET key value [ key value ... ] */ - if (redis_argkvx(r) && rnarg % 2 == 0) + if (valkey_argkvx(r) && rnarg % 2 == 0) goto error; for (uint32_t i = 2; i < rnarg; i++) { - if ((p = redis_parse_bulk(p, end, &arg, &arglen)) == NULL) + if ((p = valkey_parse_bulk(p, end, &arg, &arglen)) == NULL) goto error; - if (redis_argkvx(r) && i % 2 == 0) + if (valkey_argkvx(r) && i % 2 == 0) continue; /* not a key */ if (!push_keypos(r, arg, arglen)) goto oom; @@ -388,7 +364,7 @@ void redis_parse_cmd(struct cmd *r) { errno = EINVAL; size_t errmaxlen = 100; /* Enough for the error messages below. */ if (r->errstr == NULL) { - r->errstr = hi_malloc(errmaxlen); + r->errstr = vk_malloc(errmaxlen); if (r->errstr == NULL) { goto oom; } @@ -415,7 +391,7 @@ void redis_parse_cmd(struct cmd *r) { struct cmd *command_get(void) { struct cmd *command; - command = hi_malloc(sizeof(struct cmd)); + command = vk_malloc(sizeof(struct cmd)); if (command == NULL) { return NULL; } @@ -436,9 +412,9 @@ struct cmd *command_get(void) { command->sub_commands = NULL; command->node_addr = NULL; - command->keys = hiarray_create(1, sizeof(struct keypos)); + command->keys = vkarray_create(1, sizeof(struct keypos)); if (command->keys == NULL) { - hi_free(command); + vk_free(command); return NULL; } @@ -451,23 +427,23 @@ void command_destroy(struct cmd *command) { } if (command->cmd != NULL) { - hi_free(command->cmd); + vk_free(command->cmd); command->cmd = NULL; } if (command->errstr != NULL) { - hi_free(command->errstr); + vk_free(command->errstr); command->errstr = NULL; } if (command->keys != NULL) { command->keys->nelem = 0; - hiarray_destroy(command->keys); + vkarray_destroy(command->keys); command->keys = NULL; } if (command->frag_seq != NULL) { - hi_free(command->frag_seq); + vk_free(command->frag_seq); command->frag_seq = NULL; } @@ -482,5 +458,5 @@ void command_destroy(struct cmd *command) { command->node_addr = NULL; } - hi_free(command); + vk_free(command); } diff --git a/libvalkeycluster/command.h b/libvalkeycluster/command.h index f2d7aab6..c16cfbbe 100644 --- a/libvalkeycluster/command.h +++ b/libvalkeycluster/command.h @@ -35,7 +35,7 @@ #include #include "adlist.h" -#include +#include typedef enum cmd_parse_result { CMD_PARSE_OK, /* parsing ok */ @@ -49,15 +49,15 @@ typedef enum cmd_type { CMD_UNKNOWN, /* Request commands */ #define COMMAND(_type, _name, _subname, _arity, _keymethod, _keypos) \ - CMD_REQ_REDIS_##_type, + CMD_REQ_VALKEY_##_type, #include "cmddef.h" #undef COMMAND /* Response types */ - CMD_RSP_REDIS_STATUS, /* simple string */ - CMD_RSP_REDIS_ERROR, - CMD_RSP_REDIS_INTEGER, - CMD_RSP_REDIS_BULK, - CMD_RSP_REDIS_MULTIBULK, + CMD_RSP_VALKEY_STATUS, /* simple string */ + CMD_RSP_VALKEY_ERROR, + CMD_RSP_VALKEY_INTEGER, + CMD_RSP_VALKEY_BULK, + CMD_RSP_VALKEY_MULTIBULK, CMD_SENTINEL } cmd_type_t; @@ -80,9 +80,9 @@ struct cmd { char *cmd; uint32_t clen; /* command length */ - struct hiarray *keys; /* array of keypos, for req */ + struct vkarray *keys; /* array of keypos, for req */ - uint32_t narg; /* # arguments (redis) */ + uint32_t narg; /* # arguments (valkey) */ unsigned quit : 1; /* quit request? */ unsigned noforward : 1; /* not need forward (example: ping) */ @@ -98,12 +98,12 @@ struct cmd { struct cmd * *frag_seq; /* sequence of fragment command, map from keys to fragments*/ - redisReply *reply; + valkeyReply *reply; hilist *sub_commands; /* just for pipeline and multi-key commands */ }; -void redis_parse_cmd(struct cmd *r); +void valkey_parse_cmd(struct cmd *r); struct cmd *command_get(void); void command_destroy(struct cmd *command); diff --git a/libvalkeycluster/crc16.c b/libvalkeycluster/crc16.c index a5fb0747..982452a4 100644 --- a/libvalkeycluster/crc16.c +++ b/libvalkeycluster/crc16.c @@ -41,7 +41,7 @@ * Xor constant to output CRC : 0000 * Output for "123456789" : 31C3 */ -#include "hiutil.h" +#include "vkutil.h" static const uint16_t crc16tab[256] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, diff --git a/libvalkeycluster/dict.c b/libvalkeycluster/dict.c index 0a154499..bc98a2a5 100644 --- a/libvalkeycluster/dict.c +++ b/libvalkeycluster/dict.c @@ -34,7 +34,7 @@ */ #include -#include +#include #include #include @@ -72,7 +72,7 @@ static void _dictReset(dict *ht) { /* Create a new hash table */ dict *dictCreate(dictType *type, void *privDataPtr) { - dict *ht = hi_malloc(sizeof(*ht)); + dict *ht = vk_malloc(sizeof(*ht)); if (ht == NULL) return NULL; @@ -101,7 +101,7 @@ int dictExpand(dict *ht, unsigned long size) { _dictInit(&n, ht->type, ht->privdata); n.size = realsize; n.sizemask = realsize - 1; - n.table = hi_calloc(realsize, sizeof(dictEntry *)); + n.table = vk_calloc(realsize, sizeof(dictEntry *)); if (n.table == NULL) return DICT_ERR; @@ -131,7 +131,7 @@ int dictExpand(dict *ht, unsigned long size) { } } assert(ht->used == 0); - hi_free(ht->table); + vk_free(ht->table); /* Remap the new hashtable in the old */ *ht = n; @@ -149,7 +149,7 @@ int dictAdd(dict *ht, void *key, void *val) { return DICT_ERR; /* Allocates the memory and stores key */ - entry = hi_malloc(sizeof(*entry)); + entry = vk_malloc(sizeof(*entry)); if (entry == NULL) return DICT_ERR; @@ -177,13 +177,13 @@ static int _dictClear(dict *ht) { nextHe = he->next; dictFreeEntryKey(ht, he); dictFreeEntryVal(ht, he); - hi_free(he); + vk_free(he); ht->used--; he = nextHe; } } /* Free the table and the allocated cache structure */ - hi_free(ht->table); + vk_free(ht->table); /* Re-initialize the table */ _dictReset(ht); return DICT_OK; /* never fails */ @@ -192,7 +192,7 @@ static int _dictClear(dict *ht) { /* Clear & Release the hash table */ void dictRelease(dict *ht) { _dictClear(ht); - hi_free(ht); + vk_free(ht); } dictEntry *dictFind(dict *ht, const void *key) { diff --git a/libvalkeycluster/examples/src/clientside_caching_async.c b/libvalkeycluster/examples/src/clientside_caching_async.c index 345b399c..cb109375 100644 --- a/libvalkeycluster/examples/src/clientside_caching_async.c +++ b/libvalkeycluster/examples/src/clientside_caching_async.c @@ -4,8 +4,8 @@ * messages are received via the registered push callback. * The disconnect callback should also be used as an indication of invalidation. */ -#include -#include +#include +#include #include #include @@ -15,108 +15,108 @@ #define CLUSTER_NODE "127.0.0.1:7000" #define KEY "key:1" -void pushCallback(redisAsyncContext *ac, void *r); -void setCallback(redisClusterAsyncContext *acc, void *r, void *privdata); -void getCallback1(redisClusterAsyncContext *acc, void *r, void *privdata); -void getCallback2(redisClusterAsyncContext *acc, void *r, void *privdata); +void pushCallback(valkeyAsyncContext *ac, void *r); +void setCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata); +void getCallback1(valkeyClusterAsyncContext *acc, void *r, void *privdata); +void getCallback2(valkeyClusterAsyncContext *acc, void *r, void *privdata); void modifyKey(const char *key, const char *value); /* The connect callback enables RESP3 and client tracking. The non-const connect callback is used since we want to - set the push callback in the hiredis context. */ -void connectCallbackNC(redisAsyncContext *ac, int status) { - assert(status == REDIS_OK); - redisAsyncSetPushCallback(ac, pushCallback); - redisAsyncCommand(ac, NULL, NULL, "HELLO 3"); - redisAsyncCommand(ac, NULL, NULL, "CLIENT TRACKING ON"); + set the push callback in the libvalkey context. */ +void connectCallbackNC(valkeyAsyncContext *ac, int status) { + assert(status == VALKEY_OK); + valkeyAsyncSetPushCallback(ac, pushCallback); + valkeyAsyncCommand(ac, NULL, NULL, "HELLO 3"); + valkeyAsyncCommand(ac, NULL, NULL, "CLIENT TRACKING ON"); printf("Connected to %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } /* The event callback issues a 'SET' command when the client is ready to accept commands. A reply is expected via a call to 'setCallback()' */ -void eventCallback(const redisClusterContext *cc, int event, void *privdata) { +void eventCallback(const valkeyClusterContext *cc, int event, void *privdata) { (void)cc; - redisClusterAsyncContext *acc = (redisClusterAsyncContext *)privdata; + valkeyClusterAsyncContext *acc = (valkeyClusterAsyncContext *)privdata; /* We send our commands when the client is ready to accept commands. */ - if (event == HIRCLUSTER_EVENT_READY) { + if (event == VALKEYCLUSTER_EVENT_READY) { printf("Client is ready to accept commands\n"); int status = - redisClusterAsyncCommand(acc, setCallback, NULL, "SET %s 1", KEY); - assert(status == REDIS_OK); + valkeyClusterAsyncCommand(acc, setCallback, NULL, "SET %s 1", KEY); + assert(status == VALKEY_OK); } } /* Message callback for 'SET' commands. Issues a 'GET' command and a reply is expected as a call to 'getCallback1()' */ -void setCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { +void setCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { (void)privdata; - redisReply *reply = (redisReply *)r; + valkeyReply *reply = (valkeyReply *)r; assert(reply != NULL); printf("Callback for 'SET', reply: %s\n", reply->str); int status = - redisClusterAsyncCommand(acc, getCallback1, NULL, "GET %s", KEY); - assert(status == REDIS_OK); + valkeyClusterAsyncCommand(acc, getCallback1, NULL, "GET %s", KEY); + assert(status == VALKEY_OK); } /* Message callback for the first 'GET' command. Modifies the key to - trigger Redis to send a key invalidation message and then sends another + trigger Valkey to send a key invalidation message and then sends another 'GET' command. The invalidation message is received via the registered push callback. */ -void getCallback1(redisClusterAsyncContext *acc, void *r, void *privdata) { +void getCallback1(valkeyClusterAsyncContext *acc, void *r, void *privdata) { (void)privdata; - redisReply *reply = (redisReply *)r; + valkeyReply *reply = (valkeyReply *)r; assert(reply != NULL); printf("Callback for first 'GET', reply: %s\n", reply->str); /* Modify the key from another client which will invalidate a cached value. - Redis will send an invalidation message via a push message. */ + Valkey will send an invalidation message via a push message. */ modifyKey(KEY, "99"); int status = - redisClusterAsyncCommand(acc, getCallback2, NULL, "GET %s", KEY); - assert(status == REDIS_OK); + valkeyClusterAsyncCommand(acc, getCallback2, NULL, "GET %s", KEY); + assert(status == VALKEY_OK); } /* Push message callback handling invalidation messages. */ -void pushCallback(redisAsyncContext *ac, void *r) { - redisReply *reply = r; - if (!(reply->type == REDIS_REPLY_PUSH && reply->elements == 2 && - reply->element[0]->type == REDIS_REPLY_STRING && +void pushCallback(valkeyAsyncContext *ac, void *r) { + valkeyReply *reply = r; + if (!(reply->type == VALKEY_REPLY_PUSH && reply->elements == 2 && + reply->element[0]->type == VALKEY_REPLY_STRING && !strncmp(reply->element[0]->str, "invalidate", 10) && - reply->element[1]->type == REDIS_REPLY_ARRAY)) { + reply->element[1]->type == VALKEY_REPLY_ARRAY)) { /* Not an 'invalidate' message. Ignore. */ return; } - redisReply *payload = reply->element[1]; + valkeyReply *payload = reply->element[1]; size_t i; for (i = 0; i < payload->elements; i++) { - redisReply *key = payload->element[i]; - if (key->type == REDIS_REPLY_STRING) + valkeyReply *key = payload->element[i]; + if (key->type == VALKEY_REPLY_STRING) printf("Invalidate key '%.*s'\n", (int)key->len, key->str); - else if (key->type == REDIS_REPLY_NIL) + else if (key->type == VALKEY_REPLY_NIL) printf("Invalidate all\n"); } } /* Message callback for 'GET' commands. Exits program. */ -void getCallback2(redisClusterAsyncContext *acc, void *r, void *privdata) { +void getCallback2(valkeyClusterAsyncContext *acc, void *r, void *privdata) { (void)privdata; - redisReply *reply = (redisReply *)r; + valkeyReply *reply = (valkeyReply *)r; assert(reply != NULL); printf("Callback for second 'GET', reply: %s\n", reply->str); /* Exit the eventloop after a couple of sent commands. */ - redisClusterAsyncDisconnect(acc); + valkeyClusterAsyncDisconnect(acc); } /* A disconnect callback should invalidate all cached keys. */ -void disconnectCallback(const redisAsyncContext *ac, int status) { - assert(status == REDIS_OK); +void disconnectCallback(const valkeyAsyncContext *ac, int status) { + assert(status == VALKEY_OK); printf("Disconnected from %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); printf("Invalidate all\n"); @@ -125,43 +125,43 @@ void disconnectCallback(const redisAsyncContext *ac, int status) { /* Helper to modify keys using a separate client. */ void modifyKey(const char *key, const char *value) { printf("Modify key: '%s'\n", key); - redisClusterContext *cc = redisClusterContextInit(); - int status = redisClusterSetOptionAddNodes(cc, CLUSTER_NODE); - assert(status == REDIS_OK); - status = redisClusterConnect2(cc); - assert(status == REDIS_OK); + valkeyClusterContext *cc = valkeyClusterContextInit(); + int status = valkeyClusterSetOptionAddNodes(cc, CLUSTER_NODE); + assert(status == VALKEY_OK); + status = valkeyClusterConnect2(cc); + assert(status == VALKEY_OK); - redisReply *reply = redisClusterCommand(cc, "SET %s %s", key, value); + valkeyReply *reply = valkeyClusterCommand(cc, "SET %s %s", key, value); assert(reply != NULL); freeReplyObject(reply); - redisClusterFree(cc); + valkeyClusterFree(cc); } int main(int argc, char **argv) { - redisClusterAsyncContext *acc = redisClusterAsyncContextInit(); + valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); int status; - status = redisClusterAsyncSetConnectCallbackNC(acc, connectCallbackNC); - assert(status == REDIS_OK); - status = redisClusterAsyncSetDisconnectCallback(acc, disconnectCallback); - assert(status == REDIS_OK); - status = redisClusterSetEventCallback(acc->cc, eventCallback, acc); - assert(status == REDIS_OK); - status = redisClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE); - assert(status == REDIS_OK); + status = valkeyClusterAsyncSetConnectCallbackNC(acc, connectCallbackNC); + assert(status == VALKEY_OK); + status = valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); + assert(status == VALKEY_OK); + status = valkeyClusterSetEventCallback(acc->cc, eventCallback, acc); + assert(status == VALKEY_OK); + status = valkeyClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE); + assert(status == VALKEY_OK); struct event_base *base = event_base_new(); - status = redisClusterLibeventAttach(acc, base); - assert(status == REDIS_OK); + status = valkeyClusterLibeventAttach(acc, base); + assert(status == VALKEY_OK); - status = redisClusterAsyncConnect2(acc); - assert(status == REDIS_OK); + status = valkeyClusterAsyncConnect2(acc); + assert(status == VALKEY_OK); event_base_dispatch(base); - redisClusterAsyncFree(acc); + valkeyClusterAsyncFree(acc); event_base_free(base); return 0; } diff --git a/libvalkeycluster/examples/src/example.c b/libvalkeycluster/examples/src/example.c index a6e8041c..d3ad9f85 100644 --- a/libvalkeycluster/examples/src/example.c +++ b/libvalkeycluster/examples/src/example.c @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -7,26 +7,26 @@ int main(int argc, char **argv) { UNUSED(argv); struct timeval timeout = {1, 500000}; // 1.5s - redisClusterContext *cc = redisClusterContextInit(); - redisClusterSetOptionAddNodes(cc, "127.0.0.1:7000"); - redisClusterSetOptionConnectTimeout(cc, timeout); - redisClusterSetOptionRouteUseSlots(cc); - redisClusterConnect2(cc); + valkeyClusterContext *cc = valkeyClusterContextInit(); + valkeyClusterSetOptionAddNodes(cc, "127.0.0.1:7000"); + valkeyClusterSetOptionConnectTimeout(cc, timeout); + valkeyClusterSetOptionRouteUseSlots(cc); + valkeyClusterConnect2(cc); if (cc && cc->err) { printf("Error: %s\n", cc->errstr); // handle error exit(-1); } - redisReply *reply = - (redisReply *)redisClusterCommand(cc, "SET %s %s", "key", "value"); + valkeyReply *reply = + (valkeyReply *)valkeyClusterCommand(cc, "SET %s %s", "key", "value"); printf("SET: %s\n", reply->str); freeReplyObject(reply); - redisReply *reply2 = (redisReply *)redisClusterCommand(cc, "GET %s", "key"); + valkeyReply *reply2 = (valkeyReply *)valkeyClusterCommand(cc, "GET %s", "key"); printf("GET: %s\n", reply2->str); freeReplyObject(reply2); - redisClusterFree(cc); + valkeyClusterFree(cc); return 0; } diff --git a/libvalkeycluster/examples/src/example_async.c b/libvalkeycluster/examples/src/example_async.c index 0e91830b..df2a564b 100644 --- a/libvalkeycluster/examples/src/example_async.c +++ b/libvalkeycluster/examples/src/example_async.c @@ -1,10 +1,10 @@ -#include -#include +#include +#include #include #include -void getCallback(redisClusterAsyncContext *cc, void *r, void *privdata) { - redisReply *reply = (redisReply *)r; +void getCallback(valkeyClusterAsyncContext *cc, void *r, void *privdata) { + valkeyReply *reply = (valkeyReply *)r; if (reply == NULL) { if (cc->errstr) { printf("errstr: %s\n", cc->errstr); @@ -14,11 +14,11 @@ void getCallback(redisClusterAsyncContext *cc, void *r, void *privdata) { printf("privdata: %s reply: %s\n", (char *)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisClusterAsyncDisconnect(cc); + valkeyClusterAsyncDisconnect(cc); } -void setCallback(redisClusterAsyncContext *cc, void *r, void *privdata) { - redisReply *reply = (redisReply *)r; +void setCallback(valkeyClusterAsyncContext *cc, void *r, void *privdata) { + valkeyReply *reply = (valkeyReply *)r; if (reply == NULL) { if (cc->errstr) { printf("errstr: %s\n", cc->errstr); @@ -28,16 +28,16 @@ void setCallback(redisClusterAsyncContext *cc, void *r, void *privdata) { printf("privdata: %s reply: %s\n", (char *)privdata, reply->str); } -void connectCallback(const redisAsyncContext *ac, int status) { - if (status != REDIS_OK) { +void connectCallback(const valkeyAsyncContext *ac, int status) { + if (status != VALKEY_OK) { printf("Error: %s\n", ac->errstr); return; } printf("Connected to %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } -void disconnectCallback(const redisAsyncContext *ac, int status) { - if (status != REDIS_OK) { +void disconnectCallback(const valkeyAsyncContext *ac, int status) { + if (status != VALKEY_OK) { printf("Error: %s\n", ac->errstr); return; } @@ -46,40 +46,40 @@ void disconnectCallback(const redisAsyncContext *ac, int status) { int main(int argc, char **argv) { printf("Connecting...\n"); - redisClusterAsyncContext *cc = - redisClusterAsyncConnect("127.0.0.1:7000", HIRCLUSTER_FLAG_NULL); + valkeyClusterAsyncContext *cc = + valkeyClusterAsyncConnect("127.0.0.1:7000", VALKEYCLUSTER_FLAG_NULL); if (cc && cc->err) { printf("Error: %s\n", cc->errstr); return 1; } struct event_base *base = event_base_new(); - redisClusterLibeventAttach(cc, base); - redisClusterAsyncSetConnectCallback(cc, connectCallback); - redisClusterAsyncSetDisconnectCallback(cc, disconnectCallback); + valkeyClusterLibeventAttach(cc, base); + valkeyClusterAsyncSetConnectCallback(cc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(cc, disconnectCallback); int status; - status = redisClusterAsyncCommand(cc, setCallback, (char *)"THE_ID", + status = valkeyClusterAsyncCommand(cc, setCallback, (char *)"THE_ID", "SET %s %s", "key", "value"); - if (status != REDIS_OK) { + if (status != VALKEY_OK) { printf("error: err=%d errstr=%s\n", cc->err, cc->errstr); } - status = redisClusterAsyncCommand(cc, getCallback, (char *)"THE_ID", + status = valkeyClusterAsyncCommand(cc, getCallback, (char *)"THE_ID", "GET %s", "key"); - if (status != REDIS_OK) { + if (status != VALKEY_OK) { printf("error: err=%d errstr=%s\n", cc->err, cc->errstr); } - status = redisClusterAsyncCommand(cc, setCallback, (char *)"THE_ID", + status = valkeyClusterAsyncCommand(cc, setCallback, (char *)"THE_ID", "SET %s %s", "key2", "value2"); - if (status != REDIS_OK) { + if (status != VALKEY_OK) { printf("error: err=%d errstr=%s\n", cc->err, cc->errstr); } - status = redisClusterAsyncCommand(cc, getCallback, (char *)"THE_ID", + status = valkeyClusterAsyncCommand(cc, getCallback, (char *)"THE_ID", "GET %s", "key2"); - if (status != REDIS_OK) { + if (status != VALKEY_OK) { printf("error: err=%d errstr=%s\n", cc->err, cc->errstr); } @@ -87,7 +87,7 @@ int main(int argc, char **argv) { event_base_dispatch(base); printf("Done..\n"); - redisClusterAsyncFree(cc); + valkeyClusterAsyncFree(cc); event_base_free(base); return 0; } diff --git a/libvalkeycluster/examples/src/example_tls.c b/libvalkeycluster/examples/src/example_tls.c index b989a9e8..75cc591c 100644 --- a/libvalkeycluster/examples/src/example_tls.c +++ b/libvalkeycluster/examples/src/example_tls.c @@ -1,7 +1,7 @@ -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -11,34 +11,34 @@ int main(int argc, char **argv) { UNUSED(argc); UNUSED(argv); - redisSSLContext *ssl; - redisSSLContextError ssl_error; + valkeySSLContext *ssl; + valkeySSLContextError ssl_error; - redisInitOpenSSL(); - ssl = redisCreateSSLContext("ca.crt", NULL, "client.crt", "client.key", + valkeyInitOpenSSL(); + ssl = valkeyCreateSSLContext("ca.crt", NULL, "client.crt", "client.key", NULL, &ssl_error); if (!ssl) { - printf("SSL Context error: %s\n", redisSSLContextGetError(ssl_error)); + printf("SSL Context error: %s\n", valkeySSLContextGetError(ssl_error)); exit(1); } struct timeval timeout = {1, 500000}; // 1.5s - redisClusterContext *cc = redisClusterContextInit(); - redisClusterSetOptionAddNodes(cc, CLUSTER_NODE_TLS); - redisClusterSetOptionConnectTimeout(cc, timeout); - redisClusterSetOptionRouteUseSlots(cc); - redisClusterSetOptionParseSlaves(cc); - redisClusterSetOptionEnableSSL(cc, ssl); - redisClusterConnect2(cc); + valkeyClusterContext *cc = valkeyClusterContextInit(); + valkeyClusterSetOptionAddNodes(cc, CLUSTER_NODE_TLS); + valkeyClusterSetOptionConnectTimeout(cc, timeout); + valkeyClusterSetOptionRouteUseSlots(cc); + valkeyClusterSetOptionParseSlaves(cc); + valkeyClusterSetOptionEnableSSL(cc, ssl); + valkeyClusterConnect2(cc); if (cc && cc->err) { printf("Error: %s\n", cc->errstr); // handle error exit(-1); } - redisReply *reply = - (redisReply *)redisClusterCommand(cc, "SET %s %s", "key", "value"); + valkeyReply *reply = + (valkeyReply *)valkeyClusterCommand(cc, "SET %s %s", "key", "value"); if (!reply) { printf("Reply missing: %s\n", cc->errstr); exit(-1); @@ -46,7 +46,7 @@ int main(int argc, char **argv) { printf("SET: %s\n", reply->str); freeReplyObject(reply); - redisReply *reply2 = (redisReply *)redisClusterCommand(cc, "GET %s", "key"); + valkeyReply *reply2 = (valkeyReply *)valkeyClusterCommand(cc, "GET %s", "key"); if (!reply2) { printf("Reply missing: %s\n", cc->errstr); exit(-1); @@ -54,7 +54,7 @@ int main(int argc, char **argv) { printf("GET: %s\n", reply2->str); freeReplyObject(reply2); - redisClusterFree(cc); - redisFreeSSLContext(ssl); + valkeyClusterFree(cc); + valkeyFreeSSLContext(ssl); return 0; } diff --git a/libvalkeycluster/gencommands.py b/libvalkeycluster/gencommands.py index cc5235c7..5944e4bb 100755 --- a/libvalkeycluster/gencommands.py +++ b/libvalkeycluster/gencommands.py @@ -3,16 +3,16 @@ # Copyright (C) 2023 Viktor Soderqvist # This file is released under the BSD license, see the COPYING file -# This script generates cmddef.h from the JSON files in the Redis repo +# This script generates cmddef.h from the JSON files in the Valkey repo # describing the commands. This is done manually when commands have been added -# to Redis or when you want add more commands implemented in modules, etc. +# to Valkey or when you want add more commands implemented in modules, etc. # -# Usage: ./gencommands.py path/to/redis/src/commands/*.json > cmddef.h +# Usage: ./gencommands.py path/to/valkey/src/commands/*.json > cmddef.h # # Alternatively, the output of the script utils/generate-commands-json.py (which -# fetches the command metadata from a running Redis node) or the file -# commands.json from the redis-doc repo can be used as input to this script: -# https://github.com/redis/redis-doc/blob/master/commands.json +# fetches the command metadata from a running Valkey node) or the file +# commands.json from the valkey-doc repo can be used as input to this script: +# https://github.com/valkey-io/valkey-doc/blob/master/commands.json # # Additional JSON files can be added to extend support for custom commands. The # JSON file format is not fully documented but hopefully the format can be @@ -20,9 +20,9 @@ # the source code of this script to see what it does. # # The key specifications part is documented here: -# https://redis.io/docs/reference/key-specs/ +# https://valkey.io/docs/reference/key-specs/ # -# The discussion where this JSON format was added in Redis is here: +# The discussion where this JSON format was added in Valkey is here: # https://github.com/redis/redis/issues/9359 # # For convenience, files on the output format like cmddef.h can also be used as @@ -83,7 +83,7 @@ def firstkey(props): # indicated by a keyword like KEYS or STREAMS). begin_search = props["key_specs"][0]["begin_search"] if "index" in begin_search: - # Redis source JSON files have this syntax + # Valkey source JSON files have this syntax pos = begin_search["index"]["pos"] elif begin_search.get("type") == "index" and "spec" in begin_search: # generate-commands-json.py returns this syntax @@ -94,7 +94,7 @@ def firstkey(props): find_keys = props["key_specs"][0]["find_keys"] if "range" in find_keys or find_keys.get("type") == "range": # The first key is the arg at index pos. - # Redis source JSON files have this syntax: + # Valkey source JSON files have this syntax: # "find_keys": { # "range": {...} # } @@ -106,7 +106,7 @@ def firstkey(props): return ("INDEX", pos) elif "keynum" in find_keys: # The arg at pos is the number of keys and the next arg is the first key - # Redis source JSON files have this syntax + # Valkey source JSON files have this syntax assert find_keys["keynum"]["keynumidx"] == 0 assert find_keys["keynum"]["firstkey"] == 1 return ("KEYNUM", pos) @@ -210,17 +210,17 @@ def generate_c_code(commands): # MAIN if len(sys.argv) < 2 or sys.argv[1] == "--help": - print("Usage: %s path/to/redis/src/commands/*.json > cmddef.h" % sys.argv[0]) + print("Usage: %s path/to/valkey/src/commands/*.json > cmddef.h" % sys.argv[0]) exit(1) # Find all JSON files filenames = [] for filename in sys.argv[1:]: if os.path.isdir(filename): - # A redis repo root dir (accepted for backward compatibility) + # A valkey repo root dir (accepted for backward compatibility) jsondir = os.path.join(filename, "src", "commands") if not os.path.isdir(jsondir): - print("The directory %s is not a Redis source directory." % filename) + print("The directory %s is not a Valkey source directory." % filename) exit(1) filenames += glob.glob(os.path.join(jsondir, "*.json")) diff --git a/libvalkeycluster/tests/clusterclient.c b/libvalkeycluster/tests/clusterclient.c index 35657a9a..7ef38bf2 100644 --- a/libvalkeycluster/tests/clusterclient.c +++ b/libvalkeycluster/tests/clusterclient.c @@ -14,22 +14,22 @@ * 2 - Client failed to get initial slotmap from given "HOST:PORT". */ -#include "hircluster.h" +#include "valkeycluster.h" #include "win32.h" #include #include #include -void printReply(const redisReply *reply) { +void printReply(const valkeyReply *reply) { switch (reply->type) { - case REDIS_REPLY_ERROR: - case REDIS_REPLY_STATUS: - case REDIS_REPLY_STRING: - case REDIS_REPLY_VERB: - case REDIS_REPLY_BIGNUM: + case VALKEY_REPLY_ERROR: + case VALKEY_REPLY_STATUS: + case VALKEY_REPLY_STRING: + case VALKEY_REPLY_VERB: + case VALKEY_REPLY_BIGNUM: printf("%s\n", reply->str); break; - case REDIS_REPLY_INTEGER: + case VALKEY_REPLY_INTEGER: printf("%lld\n", reply->integer); break; default: @@ -37,18 +37,18 @@ void printReply(const redisReply *reply) { } } -void eventCallback(const redisClusterContext *cc, int event, void *privdata) { +void eventCallback(const valkeyClusterContext *cc, int event, void *privdata) { (void)cc; (void)privdata; char *e = NULL; switch (event) { - case HIRCLUSTER_EVENT_SLOTMAP_UPDATED: + case VALKEYCLUSTER_EVENT_SLOTMAP_UPDATED: e = "slotmap-updated"; break; - case HIRCLUSTER_EVENT_READY: + case VALKEYCLUSTER_EVENT_READY: e = "ready"; break; - case HIRCLUSTER_EVENT_FREE_CONTEXT: + case VALKEYCLUSTER_EVENT_FREE_CONTEXT: e = "free-context"; break; default: @@ -84,17 +84,17 @@ int main(int argc, char **argv) { struct timeval timeout = {1, 500000}; // 1.5s - redisClusterContext *cc = redisClusterContextInit(); - redisClusterSetOptionAddNodes(cc, initnode); - redisClusterSetOptionConnectTimeout(cc, timeout); + valkeyClusterContext *cc = valkeyClusterContextInit(); + valkeyClusterSetOptionAddNodes(cc, initnode); + valkeyClusterSetOptionConnectTimeout(cc, timeout); if (use_cluster_slots) { - redisClusterSetOptionRouteUseSlots(cc); + valkeyClusterSetOptionRouteUseSlots(cc); } if (show_events) { - redisClusterSetEventCallback(cc, eventCallback, NULL); + valkeyClusterSetEventCallback(cc, eventCallback, NULL); } - if (redisClusterConnect2(cc) != REDIS_OK) { + if (valkeyClusterConnect2(cc) != VALKEY_OK) { printf("Connect error: %s\n", cc->errstr); exit(2); } @@ -116,13 +116,13 @@ int main(int argc, char **argv) { } if (send_to_all) { - nodeIterator ni; - initNodeIterator(&ni, cc); + valkeyClusterNodeIterator ni; + valkeyClusterInitNodeIterator(&ni, cc); - redisClusterNode *node; - while ((node = nodeNext(&ni)) != NULL) { - redisReply *reply = - redisClusterCommandToNode(cc, node, command); + valkeyClusterNode *node; + while ((node = valkeyClusterNodeNext(&ni)) != NULL) { + valkeyReply *reply = + valkeyClusterCommandToNode(cc, node, command); if (!reply || cc->err) { printf("error: %s\n", cc->errstr); } else { @@ -135,7 +135,7 @@ int main(int argc, char **argv) { } } } else { - redisReply *reply = redisClusterCommand(cc, command); + valkeyReply *reply = valkeyClusterCommand(cc, command); if (!reply || cc->err) { printf("error: %s\n", cc->errstr); } else { @@ -145,6 +145,6 @@ int main(int argc, char **argv) { } } - redisClusterFree(cc); + valkeyClusterFree(cc); return 0; } diff --git a/libvalkeycluster/tests/clusterclient_async.c b/libvalkeycluster/tests/clusterclient_async.c index f6f5bd68..3a35a199 100644 --- a/libvalkeycluster/tests/clusterclient_async.c +++ b/libvalkeycluster/tests/clusterclient_async.c @@ -34,7 +34,7 @@ */ #include "adapters/libevent.h" -#include "hircluster.h" +#include "valkeycluster.h" #include "test_utils.h" #include #include @@ -52,16 +52,16 @@ int send_to_all = 0; void sendNextCommand(int, short, void *); -void printReply(const redisReply *reply) { +void printReply(const valkeyReply *reply) { switch (reply->type) { - case REDIS_REPLY_ERROR: - case REDIS_REPLY_STATUS: - case REDIS_REPLY_STRING: - case REDIS_REPLY_VERB: - case REDIS_REPLY_BIGNUM: + case VALKEY_REPLY_ERROR: + case VALKEY_REPLY_STATUS: + case VALKEY_REPLY_STRING: + case VALKEY_REPLY_VERB: + case VALKEY_REPLY_BIGNUM: printf("%s\n", reply->str); break; - case REDIS_REPLY_INTEGER: + case VALKEY_REPLY_INTEGER: printf("%lld\n", reply->integer); break; default: @@ -69,8 +69,8 @@ void printReply(const redisReply *reply) { } } -void replyCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { - redisReply *reply = (redisReply *)r; +void replyCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { + valkeyReply *reply = (valkeyReply *)r; intptr_t cmd_id = (intptr_t)privdata; /* Id to corresponding cmd */ if (reply == NULL) { @@ -82,8 +82,8 @@ void replyCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { if (resend_failed_cmd) { printf("resend '%s'\n", cmd_history[cmd_id]); - if (redisClusterAsyncCommand(acc, replyCallback, (void *)cmd_id, - cmd_history[cmd_id]) != REDIS_OK) + if (valkeyClusterAsyncCommand(acc, replyCallback, (void *)cmd_id, + cmd_history[cmd_id]) != VALKEY_OK) printf("send error\n"); return; } @@ -101,7 +101,7 @@ void replyCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { void sendNextCommand(int fd, short kind, void *arg) { UNUSED(fd); UNUSED(kind); - redisClusterAsyncContext *acc = arg; + valkeyClusterAsyncContext *acc = arg; int async = 0; char cmd[CMD_SIZE]; @@ -143,21 +143,21 @@ void sendNextCommand(int fd, short kind, void *arg) { strcpy(cmd_history[num_running], cmd); if (send_to_all) { - nodeIterator ni; - initNodeIterator(&ni, acc->cc); + valkeyClusterNodeIterator ni; + valkeyClusterInitNodeIterator(&ni, acc->cc); - redisClusterNode *node; - while ((node = nodeNext(&ni)) != NULL) { - int status = redisClusterAsyncCommandToNode( + valkeyClusterNode *node; + while ((node = valkeyClusterNodeNext(&ni)) != NULL) { + int status = valkeyClusterAsyncCommandToNode( acc, node, replyCallback, (void *)((intptr_t)num_running), cmd); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); num_running++; } } else { - int status = redisClusterAsyncCommand( + int status = valkeyClusterAsyncCommand( acc, replyCallback, (void *)((intptr_t)num_running), cmd); - if (status == REDIS_OK) { + if (status == VALKEY_OK) { num_running++; } else { printf("error: %s\n", acc->errstr); @@ -175,21 +175,21 @@ void sendNextCommand(int fd, short kind, void *arg) { } /* Disconnect if nothing is left to read from stdin */ - redisClusterAsyncDisconnect(acc); + valkeyClusterAsyncDisconnect(acc); } -void eventCallback(const redisClusterContext *cc, int event, void *privdata) { +void eventCallback(const valkeyClusterContext *cc, int event, void *privdata) { (void)cc; (void)privdata; char *e = NULL; switch (event) { - case HIRCLUSTER_EVENT_SLOTMAP_UPDATED: + case VALKEYCLUSTER_EVENT_SLOTMAP_UPDATED: e = "slotmap-updated"; break; - case HIRCLUSTER_EVENT_READY: + case VALKEYCLUSTER_EVENT_READY: e = "ready"; break; - case HIRCLUSTER_EVENT_FREE_CONTEXT: + case VALKEYCLUSTER_EVENT_FREE_CONTEXT: e = "free-context"; break; default: @@ -221,34 +221,34 @@ int main(int argc, char **argv) { const char *initnode = argv[optind]; struct timeval timeout = {0, 500000}; - redisClusterAsyncContext *acc = redisClusterAsyncContextInit(); + valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); - redisClusterSetOptionAddNodes(acc->cc, initnode); - redisClusterSetOptionTimeout(acc->cc, timeout); - redisClusterSetOptionConnectTimeout(acc->cc, timeout); - redisClusterSetOptionMaxRetry(acc->cc, 1); + valkeyClusterSetOptionAddNodes(acc->cc, initnode); + valkeyClusterSetOptionTimeout(acc->cc, timeout); + valkeyClusterSetOptionConnectTimeout(acc->cc, timeout); + valkeyClusterSetOptionMaxRetry(acc->cc, 1); if (use_cluster_slots) { - redisClusterSetOptionRouteUseSlots(acc->cc); + valkeyClusterSetOptionRouteUseSlots(acc->cc); } if (show_events) { - redisClusterSetEventCallback(acc->cc, eventCallback, NULL); + valkeyClusterSetEventCallback(acc->cc, eventCallback, NULL); } - if (redisClusterConnect2(acc->cc) != REDIS_OK) { + if (valkeyClusterConnect2(acc->cc) != VALKEY_OK) { printf("Connect error: %s\n", acc->cc->errstr); exit(2); } struct event_base *base = event_base_new(); - int status = redisClusterLibeventAttach(acc, base); - assert(status == REDIS_OK); + int status = valkeyClusterLibeventAttach(acc, base); + assert(status == VALKEY_OK); /* Schedule a read from stdin and send next command */ event_base_once(acc->adapter, -1, EV_TIMEOUT, sendNextCommand, acc, NULL); event_base_dispatch(base); - redisClusterAsyncFree(acc); + valkeyClusterAsyncFree(acc); event_base_free(base); return 0; } diff --git a/libvalkeycluster/tests/clusterclient_reconnect_async.c b/libvalkeycluster/tests/clusterclient_reconnect_async.c index dc852d94..e6b6b8de 100644 --- a/libvalkeycluster/tests/clusterclient_reconnect_async.c +++ b/libvalkeycluster/tests/clusterclient_reconnect_async.c @@ -1,16 +1,16 @@ /* - * This program connects to a Redis node and then reads commands from stdin, such + * This program connects to a Valkey node and then reads commands from stdin, such * as "SET foo bar", one per line and prints the results to stdout. * * The behaviour is similar to that of clusterclient_async.c, but it sends the * next command after receiving a reply from the previous command. It also works - * for standalone Redis nodes (without cluster mode), and uses the - * redisClusterAsyncCommandToNode function to send the command to the first node. + * for standalone Valkey nodes (without cluster mode), and uses the + * valkeyClusterAsyncCommandToNode function to send the command to the first node. * If it receives any I/O error, the program performs a reconnect. */ #include "adapters/libevent.h" -#include "hircluster.h" +#include "valkeycluster.h" #include "test_utils.h" #include #include @@ -18,18 +18,18 @@ #include /* Unfortunately there is no error code for this error to match */ -#define REDIS_ENOCLUSTER "ERR This instance has cluster support disabled" +#define VALKEY_ENOCLUSTER "ERR This instance has cluster support disabled" void sendNextCommand(int, short, void *); -void connectToRedis(redisClusterAsyncContext *acc) { - /* reset Redis context in case of reconnect */ - redisClusterAsyncDisconnect(acc); +void connectToValkey(valkeyClusterAsyncContext *acc) { + /* reset context in case of reconnect */ + valkeyClusterAsyncDisconnect(acc); - int status = redisClusterConnect2(acc->cc); - if (status == REDIS_OK) { + int status = valkeyClusterConnect2(acc->cc); + if (status == VALKEY_OK) { // cluster mode - } else if (acc->cc->err && strcmp(acc->cc->errstr, REDIS_ENOCLUSTER) == 0) { + } else if (acc->cc->err && strcmp(acc->cc->errstr, VALKEY_ENOCLUSTER) == 0) { printf("[no cluster]\n"); acc->cc->err = 0; memset(acc->cc->errstr, '\0', strlen(acc->cc->errstr)); @@ -39,14 +39,14 @@ void connectToRedis(redisClusterAsyncContext *acc) { } } -void replyCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { +void replyCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { UNUSED(privdata); - redisReply *reply = (redisReply *)r; + valkeyReply *reply = (valkeyReply *)r; if (reply == NULL) { - if (acc->err == REDIS_ERR_IO || acc->err == REDIS_ERR_EOF) { + if (acc->err == VALKEY_ERR_IO || acc->err == VALKEY_ERR_EOF) { printf("[reconnect]\n"); - connectToRedis(acc); + connectToValkey(acc); } else if (acc->err) { printf("error: %s\n", acc->errstr); } else { @@ -63,7 +63,7 @@ void replyCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { void sendNextCommand(int fd, short kind, void *arg) { UNUSED(fd); UNUSED(kind); - redisClusterAsyncContext *acc = arg; + valkeyClusterAsyncContext *acc = arg; char command[256]; if (fgets(command, 256, stdin)) { @@ -76,16 +76,16 @@ void sendNextCommand(int fd, short kind, void *arg) { dictEntry *de = dictNext(&di); assert(de); - redisClusterNode *node = dictGetEntryVal(de); + valkeyClusterNode *node = dictGetEntryVal(de); assert(node); // coverity[tainted_scalar] - int status = redisClusterAsyncCommandToNode(acc, node, replyCallback, + int status = valkeyClusterAsyncCommandToNode(acc, node, replyCallback, NULL, command); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); } else { // disconnect if nothing is left to read from stdin - redisClusterAsyncDisconnect(acc); + valkeyClusterAsyncDisconnect(acc); } } @@ -96,22 +96,22 @@ int main(int argc, char **argv) { } const char *initnode = argv[1]; - redisClusterAsyncContext *acc = redisClusterAsyncContextInit(); + valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); - redisClusterSetOptionAddNodes(acc->cc, initnode); - redisClusterSetOptionRouteUseSlots(acc->cc); + valkeyClusterSetOptionAddNodes(acc->cc, initnode); + valkeyClusterSetOptionRouteUseSlots(acc->cc); struct event_base *base = event_base_new(); - int status = redisClusterLibeventAttach(acc, base); - assert(status == REDIS_OK); + int status = valkeyClusterLibeventAttach(acc, base); + assert(status == VALKEY_OK); - connectToRedis(acc); + connectToValkey(acc); // schedule reading from stdin and sending next command event_base_once(acc->adapter, -1, EV_TIMEOUT, sendNextCommand, acc, NULL); event_base_dispatch(base); - redisClusterAsyncFree(acc); + valkeyClusterAsyncFree(acc); event_base_free(base); return 0; } diff --git a/libvalkeycluster/tests/ct_async.c b/libvalkeycluster/tests/ct_async.c index 008e5683..af8789e9 100644 --- a/libvalkeycluster/tests/ct_async.c +++ b/libvalkeycluster/tests/ct_async.c @@ -1,5 +1,5 @@ #include "adapters/libevent.h" -#include "hircluster.h" +#include "valkeycluster.h" #include "test_utils.h" #include #include @@ -7,104 +7,99 @@ #define CLUSTER_NODE "127.0.0.1:7000" -void getCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { +void getCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { UNUSED(privdata); - redisReply *reply = (redisReply *)r; + valkeyReply *reply = (valkeyReply *)r; ASSERT_MSG(reply != NULL, acc->errstr); /* Disconnect after receiving the first reply to GET */ - redisClusterAsyncDisconnect(acc); + valkeyClusterAsyncDisconnect(acc); } -void setCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { +void setCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { UNUSED(privdata); - redisReply *reply = (redisReply *)r; + valkeyReply *reply = (valkeyReply *)r; ASSERT_MSG(reply != NULL, acc->errstr); } -void connectCallback(const redisAsyncContext *ac, int status) { - ASSERT_MSG(status == REDIS_OK, ac->errstr); +void connectCallback(const valkeyAsyncContext *ac, int status) { + ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Connected to %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } -#ifndef HIRCLUSTER_NO_NONCONST_CONNECT_CB -void connectCallbackNC(redisAsyncContext *ac, int status) { +void connectCallbackNC(valkeyAsyncContext *ac, int status) { UNUSED(ac); UNUSED(status); /* The testcase expects a failure during registration of this non-const connect callback and it should never be called. */ assert(0); } -#endif -void disconnectCallback(const redisAsyncContext *ac, int status) { - ASSERT_MSG(status == REDIS_OK, ac->errstr); +void disconnectCallback(const valkeyAsyncContext *ac, int status) { + ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Disconnected from %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } -void eventCallback(const redisClusterContext *cc, int event, void *privdata) { +void eventCallback(const valkeyClusterContext *cc, int event, void *privdata) { (void)cc; - redisClusterAsyncContext *acc = (redisClusterAsyncContext *)privdata; + valkeyClusterAsyncContext *acc = (valkeyClusterAsyncContext *)privdata; /* We send our commands when the client is ready to accept commands. */ - if (event == HIRCLUSTER_EVENT_READY) { + if (event == VALKEYCLUSTER_EVENT_READY) { int status; - status = redisClusterAsyncCommand(acc, setCallback, (char *)"ID", + status = valkeyClusterAsyncCommand(acc, setCallback, (char *)"ID", "SET key12345 value"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); /* This command will trigger a disconnect in its reply callback. */ - status = redisClusterAsyncCommand(acc, getCallback, (char *)"ID", + status = valkeyClusterAsyncCommand(acc, getCallback, (char *)"ID", "GET key12345"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); - status = redisClusterAsyncCommand(acc, setCallback, (char *)"ID", + status = valkeyClusterAsyncCommand(acc, setCallback, (char *)"ID", "SET key23456 value2"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); - status = redisClusterAsyncCommand(acc, getCallback, (char *)"ID", + status = valkeyClusterAsyncCommand(acc, getCallback, (char *)"ID", "GET key23456"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); } } int main(void) { - redisClusterAsyncContext *acc = redisClusterAsyncContextInit(); + valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); int status; - status = redisClusterAsyncSetConnectCallback(acc, connectCallback); - assert(status == REDIS_OK); - status = redisClusterAsyncSetConnectCallback(acc, connectCallback); - assert(status == REDIS_ERR); /* Re-registration not accepted */ - -#ifndef HIRCLUSTER_NO_NONCONST_CONNECT_CB - status = redisClusterAsyncSetConnectCallbackNC(acc, connectCallbackNC); - assert(status == REDIS_ERR); /* Re-registration not accepted */ -#endif - - status = redisClusterAsyncSetDisconnectCallback(acc, disconnectCallback); - assert(status == REDIS_OK); - status = redisClusterSetEventCallback(acc->cc, eventCallback, acc); - assert(status == REDIS_OK); - status = redisClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE); - assert(status == REDIS_OK); + status = valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + assert(status == VALKEY_OK); + status = valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + assert(status == VALKEY_ERR); /* Re-registration not accepted */ + status = valkeyClusterAsyncSetConnectCallbackNC(acc, connectCallbackNC); + assert(status == VALKEY_ERR); /* Re-registration not accepted */ + + status = valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); + assert(status == VALKEY_OK); + status = valkeyClusterSetEventCallback(acc->cc, eventCallback, acc); + assert(status == VALKEY_OK); + status = valkeyClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE); + assert(status == VALKEY_OK); /* Expect error when connecting without an attached event library. */ - status = redisClusterAsyncConnect2(acc); - assert(status == REDIS_ERR); + status = valkeyClusterAsyncConnect2(acc); + assert(status == VALKEY_ERR); struct event_base *base = event_base_new(); - status = redisClusterLibeventAttach(acc, base); - assert(status == REDIS_OK); + status = valkeyClusterLibeventAttach(acc, base); + assert(status == VALKEY_OK); - status = redisClusterAsyncConnect2(acc); - assert(status == REDIS_OK); + status = valkeyClusterAsyncConnect2(acc); + assert(status == VALKEY_OK); event_base_dispatch(base); - redisClusterAsyncFree(acc); + valkeyClusterAsyncFree(acc); event_base_free(base); return 0; } diff --git a/libvalkeycluster/tests/ct_async_glib.c b/libvalkeycluster/tests/ct_async_glib.c index 6eed4a32..44bd160c 100644 --- a/libvalkeycluster/tests/ct_async_glib.c +++ b/libvalkeycluster/tests/ct_async_glib.c @@ -1,5 +1,5 @@ #include "adapters/glib.h" -#include "hircluster.h" +#include "valkeycluster.h" #include "test_utils.h" #include @@ -7,29 +7,29 @@ static GMainLoop *mainloop; -void setCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { +void setCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { UNUSED(privdata); - redisReply *reply = (redisReply *)r; + valkeyReply *reply = (valkeyReply *)r; ASSERT_MSG(reply != NULL, acc->errstr); } -void getCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { +void getCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { UNUSED(privdata); - redisReply *reply = (redisReply *)r; + valkeyReply *reply = (valkeyReply *)r; ASSERT_MSG(reply != NULL, acc->errstr); /* Disconnect after receiving the first reply to GET */ - redisClusterAsyncDisconnect(acc); + valkeyClusterAsyncDisconnect(acc); g_main_loop_quit(mainloop); } -void connectCallback(const redisAsyncContext *ac, int status) { - ASSERT_MSG(status == REDIS_OK, ac->errstr); +void connectCallback(const valkeyAsyncContext *ac, int status) { + ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Connected to %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } -void disconnectCallback(const redisAsyncContext *ac, int status) { - ASSERT_MSG(status == REDIS_OK, ac->errstr); +void disconnectCallback(const valkeyAsyncContext *ac, int status) { + ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Disconnected from %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } @@ -40,27 +40,27 @@ int main(int argc, char **argv) { GMainContext *context = NULL; mainloop = g_main_loop_new(context, FALSE); - redisClusterAsyncContext *acc = - redisClusterAsyncConnect(CLUSTER_NODE, HIRCLUSTER_FLAG_NULL); + valkeyClusterAsyncContext *acc = + valkeyClusterAsyncConnect(CLUSTER_NODE, VALKEYCLUSTER_FLAG_NULL); assert(acc); ASSERT_MSG(acc->err == 0, acc->errstr); int status; - redisClusterGlibAdapter adapter = {.context = context}; - status = redisClusterGlibAttach(acc, &adapter); - assert(status == REDIS_OK); + valkeyClusterGlibAdapter adapter = {.context = context}; + status = valkeyClusterGlibAttach(acc, &adapter); + assert(status == VALKEY_OK); - redisClusterAsyncSetConnectCallback(acc, connectCallback); - redisClusterAsyncSetDisconnectCallback(acc, disconnectCallback); + valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); - status = redisClusterAsyncCommand(acc, setCallback, "id", "SET key value"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + status = valkeyClusterAsyncCommand(acc, setCallback, "id", "SET key value"); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); - status = redisClusterAsyncCommand(acc, getCallback, "id", "GET key"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + status = valkeyClusterAsyncCommand(acc, getCallback, "id", "GET key"); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); g_main_loop_run(mainloop); - redisClusterAsyncFree(acc); + valkeyClusterAsyncFree(acc); return 0; } diff --git a/libvalkeycluster/tests/ct_async_libev.c b/libvalkeycluster/tests/ct_async_libev.c index 83cae20e..59663e86 100644 --- a/libvalkeycluster/tests/ct_async_libev.c +++ b/libvalkeycluster/tests/ct_async_libev.c @@ -1,32 +1,32 @@ #include "adapters/libev.h" -#include "hircluster.h" +#include "valkeycluster.h" #include "test_utils.h" #include #define CLUSTER_NODE "127.0.0.1:7000" -void setCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { +void setCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { UNUSED(privdata); - redisReply *reply = (redisReply *)r; + valkeyReply *reply = (valkeyReply *)r; ASSERT_MSG(reply != NULL, acc->errstr); } -void getCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { +void getCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { UNUSED(privdata); - redisReply *reply = (redisReply *)r; + valkeyReply *reply = (valkeyReply *)r; ASSERT_MSG(reply != NULL, acc->errstr); /* Disconnect after receiving the first reply to GET */ - redisClusterAsyncDisconnect(acc); + valkeyClusterAsyncDisconnect(acc); } -void connectCallback(const redisAsyncContext *ac, int status) { - ASSERT_MSG(status == REDIS_OK, ac->errstr); +void connectCallback(const valkeyAsyncContext *ac, int status) { + ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Connected to %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } -void disconnectCallback(const redisAsyncContext *ac, int status) { - ASSERT_MSG(status == REDIS_OK, ac->errstr); +void disconnectCallback(const valkeyAsyncContext *ac, int status) { + ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Disconnected from %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } @@ -34,28 +34,28 @@ int main(int argc, char **argv) { UNUSED(argc); UNUSED(argv); - redisClusterAsyncContext *acc = - redisClusterAsyncConnect(CLUSTER_NODE, HIRCLUSTER_FLAG_NULL); + valkeyClusterAsyncContext *acc = + valkeyClusterAsyncConnect(CLUSTER_NODE, VALKEYCLUSTER_FLAG_NULL); assert(acc); ASSERT_MSG(acc->err == 0, acc->errstr); int status; - status = redisClusterLibevAttach(acc, EV_DEFAULT); - assert(status == REDIS_OK); + status = valkeyClusterLibevAttach(acc, EV_DEFAULT); + assert(status == VALKEY_OK); - redisClusterAsyncSetConnectCallback(acc, connectCallback); - redisClusterAsyncSetDisconnectCallback(acc, disconnectCallback); + valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); - status = redisClusterAsyncCommand(acc, setCallback, (char *)"ID", + status = valkeyClusterAsyncCommand(acc, setCallback, (char *)"ID", "SET key value"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); status = - redisClusterAsyncCommand(acc, getCallback, (char *)"ID", "GET key"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + valkeyClusterAsyncCommand(acc, getCallback, (char *)"ID", "GET key"); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); ev_loop(EV_DEFAULT_ 0); - redisClusterAsyncFree(acc); + valkeyClusterAsyncFree(acc); return 0; } diff --git a/libvalkeycluster/tests/ct_async_libuv.c b/libvalkeycluster/tests/ct_async_libuv.c index 3ba8b6e7..beeb17c8 100644 --- a/libvalkeycluster/tests/ct_async_libuv.c +++ b/libvalkeycluster/tests/ct_async_libuv.c @@ -1,32 +1,32 @@ #include "adapters/libuv.h" -#include "hircluster.h" +#include "valkeycluster.h" #include "test_utils.h" #include #define CLUSTER_NODE "127.0.0.1:7000" -void setCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { +void setCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { UNUSED(privdata); - redisReply *reply = (redisReply *)r; + valkeyReply *reply = (valkeyReply *)r; ASSERT_MSG(reply != NULL, acc->errstr); } -void getCallback(redisClusterAsyncContext *acc, void *r, void *privdata) { +void getCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { UNUSED(privdata); - redisReply *reply = (redisReply *)r; + valkeyReply *reply = (valkeyReply *)r; ASSERT_MSG(reply != NULL, acc->errstr); /* Disconnect after receiving the first reply to GET */ - redisClusterAsyncDisconnect(acc); + valkeyClusterAsyncDisconnect(acc); } -void connectCallback(const redisAsyncContext *ac, int status) { - ASSERT_MSG(status == REDIS_OK, ac->errstr); +void connectCallback(const valkeyAsyncContext *ac, int status) { + ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Connected to %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } -void disconnectCallback(const redisAsyncContext *ac, int status) { - ASSERT_MSG(status == REDIS_OK, ac->errstr); +void disconnectCallback(const valkeyAsyncContext *ac, int status) { + ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Disconnected from %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } @@ -34,30 +34,30 @@ int main(int argc, char **argv) { UNUSED(argc); UNUSED(argv); - redisClusterAsyncContext *acc = - redisClusterAsyncConnect(CLUSTER_NODE, HIRCLUSTER_FLAG_NULL); + valkeyClusterAsyncContext *acc = + valkeyClusterAsyncConnect(CLUSTER_NODE, VALKEYCLUSTER_FLAG_NULL); assert(acc); ASSERT_MSG(acc->err == 0, acc->errstr); int status; uv_loop_t *loop = uv_default_loop(); - status = redisClusterLibuvAttach(acc, loop); - assert(status == REDIS_OK); + status = valkeyClusterLibuvAttach(acc, loop); + assert(status == VALKEY_OK); - redisClusterAsyncSetConnectCallback(acc, connectCallback); - redisClusterAsyncSetDisconnectCallback(acc, disconnectCallback); + valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); - status = redisClusterAsyncCommand(acc, setCallback, (char *)"ID", + status = valkeyClusterAsyncCommand(acc, setCallback, (char *)"ID", "SET key value"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); status = - redisClusterAsyncCommand(acc, getCallback, (char *)"ID", "GET key"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + valkeyClusterAsyncCommand(acc, getCallback, (char *)"ID", "GET key"); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); uv_run(loop, UV_RUN_DEFAULT); - redisClusterAsyncFree(acc); + valkeyClusterAsyncFree(acc); uv_loop_delete(loop); return 0; } diff --git a/libvalkeycluster/tests/ct_commands.c b/libvalkeycluster/tests/ct_commands.c index 44607950..33acaaec 100644 --- a/libvalkeycluster/tests/ct_commands.c +++ b/libvalkeycluster/tests/ct_commands.c @@ -1,4 +1,4 @@ -#include "hircluster.h" +#include "valkeycluster.h" #include "test_utils.h" #include "win32.h" #include @@ -8,91 +8,91 @@ #define CLUSTER_NODE "127.0.0.1:7000" -void test_exists(redisClusterContext *cc) { - redisReply *reply; - reply = (redisReply *)redisClusterCommand(cc, "SET key1 Hello"); +void test_exists(valkeyClusterContext *cc) { + valkeyReply *reply; + reply = (valkeyReply *)valkeyClusterCommand(cc, "SET key1 Hello"); CHECK_REPLY_OK(cc, reply); freeReplyObject(reply); - reply = (redisReply *)redisClusterCommand(cc, "EXISTS key1"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "EXISTS key1"); CHECK_REPLY_INT(cc, reply, 1); freeReplyObject(reply); - reply = (redisReply *)redisClusterCommand(cc, "EXISTS nosuchkey"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "EXISTS nosuchkey"); CHECK_REPLY_INT(cc, reply, 0); freeReplyObject(reply); - reply = (redisReply *)redisClusterCommand(cc, "SET key2 World"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "SET key2 World"); CHECK_REPLY_OK(cc, reply); freeReplyObject(reply); - reply = (redisReply *)redisClusterCommand(cc, "EXISTS key1 key2 nosuchkey"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "EXISTS key1 key2 nosuchkey"); CHECK_REPLY_INT(cc, reply, 2); freeReplyObject(reply); } -void test_bitfield(redisClusterContext *cc) { - redisReply *reply; +void test_bitfield(valkeyClusterContext *cc) { + valkeyReply *reply; - reply = (redisReply *)redisClusterCommand( + reply = (valkeyReply *)valkeyClusterCommand( cc, "BITFIELD bkey1 SET u32 #0 255 GET u32 #0"); CHECK_REPLY_ARRAY(cc, reply, 2); CHECK_REPLY_INT(cc, reply->element[1], 255); freeReplyObject(reply); } -void test_bitfield_ro(redisClusterContext *cc) { - if (redis_version_less_than(6, 0)) +void test_bitfield_ro(valkeyClusterContext *cc) { + if (valkey_version_less_than(6, 0)) return; /* Skip test, command not available. */ - redisReply *reply; + valkeyReply *reply; - reply = (redisReply *)redisClusterCommand(cc, "SET bkey2 a"); // 97 + reply = (valkeyReply *)valkeyClusterCommand(cc, "SET bkey2 a"); // 97 CHECK_REPLY_OK(cc, reply); freeReplyObject(reply); reply = - (redisReply *)redisClusterCommand(cc, "BITFIELD_RO bkey2 GET u8 #0"); + (valkeyReply *)valkeyClusterCommand(cc, "BITFIELD_RO bkey2 GET u8 #0"); CHECK_REPLY_ARRAY(cc, reply, 1); CHECK_REPLY_INT(cc, reply->element[0], 97); freeReplyObject(reply); } -void test_mset(redisClusterContext *cc) { - redisReply *reply; - reply = (redisReply *)redisClusterCommand( +void test_mset(valkeyClusterContext *cc) { + valkeyReply *reply; + reply = (valkeyReply *)valkeyClusterCommand( cc, "MSET key1 mset1 key2 mset2 key3 mset3"); CHECK_REPLY_OK(cc, reply); freeReplyObject(reply); - reply = (redisReply *)redisClusterCommand(cc, "GET key1"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "GET key1"); CHECK_REPLY_STR(cc, reply, "mset1"); freeReplyObject(reply); - reply = (redisReply *)redisClusterCommand(cc, "GET key2"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "GET key2"); CHECK_REPLY_STR(cc, reply, "mset2"); freeReplyObject(reply); - reply = (redisReply *)redisClusterCommand(cc, "GET key3"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "GET key3"); CHECK_REPLY_STR(cc, reply, "mset3"); freeReplyObject(reply); } -void test_mget(redisClusterContext *cc) { - redisReply *reply; - reply = (redisReply *)redisClusterCommand(cc, "SET key1 mget1"); +void test_mget(valkeyClusterContext *cc) { + valkeyReply *reply; + reply = (valkeyReply *)valkeyClusterCommand(cc, "SET key1 mget1"); CHECK_REPLY_OK(cc, reply); freeReplyObject(reply); - reply = (redisReply *)redisClusterCommand(cc, "SET key2 mget2"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "SET key2 mget2"); CHECK_REPLY_OK(cc, reply); freeReplyObject(reply); - reply = (redisReply *)redisClusterCommand(cc, "SET key3 mget3"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "SET key3 mget3"); CHECK_REPLY_OK(cc, reply); freeReplyObject(reply); - reply = (redisReply *)redisClusterCommand(cc, "MGET key1 key2 key3"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "MGET key1 key2 key3"); CHECK_REPLY_ARRAY(cc, reply, 3); CHECK_REPLY_STR(cc, reply->element[0], "mget1"); CHECK_REPLY_STR(cc, reply->element[1], "mget2"); @@ -100,67 +100,67 @@ void test_mget(redisClusterContext *cc) { freeReplyObject(reply); } -void test_hset_hget_hdel_hexists(redisClusterContext *cc) { - redisReply *reply; +void test_hset_hget_hdel_hexists(valkeyClusterContext *cc) { + valkeyReply *reply; // Prepare - reply = (redisReply *)redisClusterCommand(cc, "HDEL myhash field1"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "HDEL myhash field1"); CHECK_REPLY(cc, reply); freeReplyObject(reply); - reply = (redisReply *)redisClusterCommand(cc, "HDEL myhash field2"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "HDEL myhash field2"); CHECK_REPLY(cc, reply); freeReplyObject(reply); // Set hash field reply = - (redisReply *)redisClusterCommand(cc, "HSET myhash field1 hsetvalue"); + (valkeyReply *)valkeyClusterCommand(cc, "HSET myhash field1 hsetvalue"); CHECK_REPLY_INT(cc, reply, 1); // Set 1 field freeReplyObject(reply); // Set second hash field reply = - (redisReply *)redisClusterCommand(cc, "HSET myhash field3 hsetvalue3"); + (valkeyReply *)valkeyClusterCommand(cc, "HSET myhash field3 hsetvalue3"); CHECK_REPLY_INT(cc, reply, 1); // Set 1 field freeReplyObject(reply); // Get field value - reply = (redisReply *)redisClusterCommand(cc, "HGET myhash field1"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "HGET myhash field1"); CHECK_REPLY_STR(cc, reply, "hsetvalue"); freeReplyObject(reply); // Get field that is not present - reply = (redisReply *)redisClusterCommand(cc, "HGET myhash field2"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "HGET myhash field2"); CHECK_REPLY_NIL(cc, reply); freeReplyObject(reply); // Delete a field - reply = (redisReply *)redisClusterCommand(cc, "HDEL myhash field1"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "HDEL myhash field1"); CHECK_REPLY_INT(cc, reply, 1); // Delete 1 field freeReplyObject(reply); // Delete a field that is not present - reply = (redisReply *)redisClusterCommand(cc, "HDEL myhash field2"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "HDEL myhash field2"); CHECK_REPLY_INT(cc, reply, 0); // Nothing to delete freeReplyObject(reply); // Check if field exists - reply = (redisReply *)redisClusterCommand(cc, "HEXISTS myhash field3"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "HEXISTS myhash field3"); CHECK_REPLY_INT(cc, reply, 1); // exists freeReplyObject(reply); // Delete multiple fields at once - reply = (redisReply *)redisClusterCommand( + reply = (valkeyReply *)valkeyClusterCommand( cc, "HDEL myhash field1 field2 field3"); CHECK_REPLY_INT(cc, reply, 1); // field3 deleted freeReplyObject(reply); // Make sure field3 is deleted now - reply = (redisReply *)redisClusterCommand(cc, "HEXISTS myhash field3"); + reply = (valkeyReply *)valkeyClusterCommand(cc, "HEXISTS myhash field3"); CHECK_REPLY_INT(cc, reply, 0); // no field freeReplyObject(reply); // Set multiple fields at once - reply = (redisReply *)redisClusterCommand( + reply = (valkeyReply *)valkeyClusterCommand( cc, "HSET myhash field1 hsetvalue1 field2 hsetvalue2"); CHECK_REPLY_INT(cc, reply, 2); freeReplyObject(reply); @@ -168,23 +168,23 @@ void test_hset_hget_hdel_hexists(redisClusterContext *cc) { // Command layout: // eval