diff --git a/libvalkeycluster/adapters/ae.h b/libvalkeycluster/adapters/ae.h deleted file mode 100644 index 9314c2b7..00000000 --- a/libvalkeycluster/adapters/ae.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2010-2011, Pieter Noordhuis - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Redis nor the names of its contributors may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __HIREDIS_CLUSTER_AE_H__ -#define __HIREDIS_CLUSTER_AE_H__ - -#include "../hircluster.h" -#include - -static int redisAeAttach_link(redisAsyncContext *ac, void *base) { - return redisAeAttach((aeEventLoop *)base, ac); -} - -static int redisClusterAeAttach(aeEventLoop *loop, - redisClusterAsyncContext *acc) { - - if (acc == NULL || loop == NULL) { - return REDIS_ERR; - } - - acc->adapter = loop; - acc->attach_fn = redisAeAttach_link; - - return REDIS_OK; -} - -#endif diff --git a/libvalkeycluster/adapters/glib.h b/libvalkeycluster/adapters/glib.h deleted file mode 100644 index c3718a21..00000000 --- a/libvalkeycluster/adapters/glib.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2021, Björn Svensson - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Redis nor the names of its contributors may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __HIREDIS_CLUSTER_GLIB_H__ -#define __HIREDIS_CLUSTER_GLIB_H__ - -#include "../hircluster.h" -#include - -typedef struct redisClusterGlibAdapter { - GMainContext *context; -} redisClusterGlibAdapter; - -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; - } - return REDIS_ERR; -} - -static int redisClusterGlibAttach(redisClusterAsyncContext *acc, - redisClusterGlibAdapter *adapter) { - if (acc == NULL || adapter == NULL) { - return REDIS_ERR; - } - - acc->adapter = adapter; - acc->attach_fn = redisGlibAttach_link; - - return REDIS_OK; -} - -#endif diff --git a/libvalkeycluster/adapters/libev.h b/libvalkeycluster/adapters/libev.h deleted file mode 100644 index 084fd34f..00000000 --- a/libvalkeycluster/adapters/libev.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2021, Björn Svensson - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Redis nor the names of its contributors may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __HIREDIS_CLUSTER_LIBEV_H__ -#define __HIREDIS_CLUSTER_LIBEV_H__ - -#include "../hircluster.h" -#include - -static int redisLibevAttach_link(redisAsyncContext *ac, void *loop) { - return redisLibevAttach((struct ev_loop *)loop, ac); -} - -static int redisClusterLibevAttach(redisClusterAsyncContext *acc, - struct ev_loop *loop) { - if (loop == NULL || acc == NULL) { - return REDIS_ERR; - } - - acc->adapter = loop; - acc->attach_fn = redisLibevAttach_link; - - return REDIS_OK; -} - -#endif diff --git a/libvalkeycluster/adapters/libevent.h b/libvalkeycluster/adapters/libevent.h deleted file mode 100644 index 87d312f0..00000000 --- a/libvalkeycluster/adapters/libevent.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2010-2011, Pieter Noordhuis - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Redis nor the names of its contributors may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __HIREDIS_CLUSTER_LIBEVENT_H__ -#define __HIREDIS_CLUSTER_LIBEVENT_H__ - -#include "../hircluster.h" -#include - -static int redisLibeventAttach_link(redisAsyncContext *ac, void *base) { - return redisLibeventAttach(ac, (struct event_base *)base); -} - -static int redisClusterLibeventAttach(redisClusterAsyncContext *acc, - struct event_base *base) { - - if (acc == NULL || base == NULL) { - return REDIS_ERR; - } - - acc->adapter = base; - acc->attach_fn = redisLibeventAttach_link; - - return REDIS_OK; -} - -#endif diff --git a/libvalkeycluster/adapters/libuv.h b/libvalkeycluster/adapters/libuv.h deleted file mode 100644 index 527419e2..00000000 --- a/libvalkeycluster/adapters/libuv.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2021, Red Hat - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Redis nor the names of its contributors may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __HIREDIS_CLUSTER_LIBUV_H__ -#define __HIREDIS_CLUSTER_LIBUV_H__ - -#include "../hircluster.h" -#include - -static int redisLibuvAttach_link(redisAsyncContext *ac, void *loop) { - return redisLibuvAttach(ac, (uv_loop_t *)loop); -} - -static int redisClusterLibuvAttach(redisClusterAsyncContext *acc, - uv_loop_t *loop) { - - if (acc == NULL || loop == NULL) { - return REDIS_ERR; - } - - acc->adapter = loop; - acc->attach_fn = redisLibuvAttach_link; - - return REDIS_OK; -} - -#endif diff --git a/libvalkeycluster/dict.c b/libvalkeycluster/dict.c deleted file mode 100644 index 0a154499..00000000 --- a/libvalkeycluster/dict.c +++ /dev/null @@ -1,287 +0,0 @@ -/* Hash table implementation. - * - * This file implements in memory hash tables with insert/del/replace/find/ - * get-random-element operations. Hash tables will auto resize if needed - * tables of power of two in size are used, collisions are handled by - * chaining. See the source code for more information... :) - * - * Copyright (c) 2006-2010, Salvatore Sanfilippo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Redis nor the names of its contributors may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include - -#include "dict.h" - -/* -------------------------- private prototypes ---------------------------- */ - -static int _dictExpandIfNeeded(dict *ht); -static unsigned long _dictNextPower(unsigned long size); -static int _dictKeyIndex(dict *ht, const void *key); -static int _dictInit(dict *ht, dictType *type, void *privDataPtr); - -/* -------------------------- hash functions -------------------------------- */ - -/* Generic hash function (a popular one from Bernstein). - * I tested a few and this was the best. */ -unsigned int dictGenHashFunction(const unsigned char *buf, int len) { - unsigned int hash = 5381; - - while (len--) - hash = ((hash << 5) + hash) + (*buf++); /* hash * 33 + c */ - return hash; -} - -/* ----------------------------- API implementation ------------------------- */ - -/* Reset an hashtable already initialized with ht_init(). - * NOTE: This function should only called by ht_destroy(). */ -static void _dictReset(dict *ht) { - ht->table = NULL; - ht->size = 0; - ht->sizemask = 0; - ht->used = 0; -} - -/* Create a new hash table */ -dict *dictCreate(dictType *type, void *privDataPtr) { - dict *ht = hi_malloc(sizeof(*ht)); - if (ht == NULL) - return NULL; - - _dictInit(ht, type, privDataPtr); - return ht; -} - -/* Initialize the hash table */ -static int _dictInit(dict *ht, dictType *type, void *privDataPtr) { - _dictReset(ht); - ht->type = type; - ht->privdata = privDataPtr; - return DICT_OK; -} - -/* Expand or create the hashtable */ -int dictExpand(dict *ht, unsigned long size) { - dict n; /* the new hashtable */ - unsigned long realsize = _dictNextPower(size), i; - - /* the size is invalid if it is smaller than the number of - * elements already inside the hashtable */ - if (ht->used > size) - return DICT_ERR; - - _dictInit(&n, ht->type, ht->privdata); - n.size = realsize; - n.sizemask = realsize - 1; - n.table = hi_calloc(realsize, sizeof(dictEntry *)); - if (n.table == NULL) - return DICT_ERR; - - /* Copy all the elements from the old to the new table: - * note that if the old hash table is empty ht->size is zero, - * so dictExpand just creates an hash table. */ - n.used = ht->used; - for (i = 0; i < ht->size && ht->used > 0; i++) { - dictEntry *he, *nextHe; - - if (ht->table[i] == NULL) - continue; - - /* For each hash entry on this slot... */ - he = ht->table[i]; - while (he) { - unsigned int h; - - nextHe = he->next; - /* Get the new element index */ - h = dictHashKey(ht, he->key) & n.sizemask; - he->next = n.table[h]; - n.table[h] = he; - ht->used--; - /* Pass to the next element */ - he = nextHe; - } - } - assert(ht->used == 0); - hi_free(ht->table); - - /* Remap the new hashtable in the old */ - *ht = n; - return DICT_OK; -} - -/* Add an element to the target hash table */ -int dictAdd(dict *ht, void *key, void *val) { - int index; - dictEntry *entry; - - /* Get the index of the new element, or -1 if - * the element already exists. */ - if ((index = _dictKeyIndex(ht, key)) == -1) - return DICT_ERR; - - /* Allocates the memory and stores key */ - entry = hi_malloc(sizeof(*entry)); - if (entry == NULL) - return DICT_ERR; - - entry->next = ht->table[index]; - ht->table[index] = entry; - - /* Set the hash entry fields. */ - dictSetHashKey(ht, entry, key); - dictSetHashVal(ht, entry, val); - ht->used++; - return DICT_OK; -} - -/* Destroy an entire hash table */ -static int _dictClear(dict *ht) { - unsigned long i; - - /* Free all the elements */ - for (i = 0; i < ht->size && ht->used > 0; i++) { - dictEntry *he, *nextHe; - - if ((he = ht->table[i]) == NULL) - continue; - while (he) { - nextHe = he->next; - dictFreeEntryKey(ht, he); - dictFreeEntryVal(ht, he); - hi_free(he); - ht->used--; - he = nextHe; - } - } - /* Free the table and the allocated cache structure */ - hi_free(ht->table); - /* Re-initialize the table */ - _dictReset(ht); - return DICT_OK; /* never fails */ -} - -/* Clear & Release the hash table */ -void dictRelease(dict *ht) { - _dictClear(ht); - hi_free(ht); -} - -dictEntry *dictFind(dict *ht, const void *key) { - dictEntry *he; - unsigned int h; - - if (ht->size == 0) - return NULL; - h = dictHashKey(ht, key) & ht->sizemask; - he = ht->table[h]; - while (he) { - if (dictCompareHashKeys(ht, key, he->key)) - return he; - he = he->next; - } - return NULL; -} - -void dictInitIterator(dictIterator *iter, dict *ht) { - iter->ht = ht; - iter->index = -1; - iter->entry = NULL; - iter->nextEntry = NULL; -} - -dictEntry *dictNext(dictIterator *iter) { - while (1) { - if (iter->entry == NULL) { - iter->index++; - if (iter->index >= (signed)iter->ht->size) - break; - iter->entry = iter->ht->table[iter->index]; - } else { - iter->entry = iter->nextEntry; - } - if (iter->entry) { - /* We need to save the 'next' here, the iterator user - * may delete the entry we are returning. */ - iter->nextEntry = iter->entry->next; - return iter->entry; - } - } - return NULL; -} - -/* ------------------------- private functions ------------------------------ */ - -/* Expand the hash table if needed */ -static int _dictExpandIfNeeded(dict *ht) { - /* If the hash table is empty expand it to the initial size, - * if the table is "full" double its size. */ - if (ht->size == 0) - return dictExpand(ht, DICT_HT_INITIAL_SIZE); - if (ht->used == ht->size) - return dictExpand(ht, ht->size * 2); - return DICT_OK; -} - -/* Our hash table capability is a power of two */ -static unsigned long _dictNextPower(unsigned long size) { - unsigned long i = DICT_HT_INITIAL_SIZE; - - if (size >= LONG_MAX) - return LONG_MAX; - while (1) { - if (i >= size) - return i; - i *= 2; - } -} - -/* Returns the index of a free slot that can be populated with - * an hash entry for the given 'key'. - * If the key already exists, -1 is returned. */ -static int _dictKeyIndex(dict *ht, const void *key) { - unsigned int h; - dictEntry *he; - - /* Expand the hashtable if needed */ - if (_dictExpandIfNeeded(ht) == DICT_ERR) - return -1; - /* Compute the key hash value */ - h = dictHashKey(ht, key) & ht->sizemask; - /* Search if this slot does not already contain the given key */ - he = ht->table[h]; - while (he) { - if (dictCompareHashKeys(ht, key, he->key)) - return -1; - he = he->next; - } - return h; -} diff --git a/libvalkeycluster/dict.h b/libvalkeycluster/dict.h deleted file mode 100644 index 7e1d70d0..00000000 --- a/libvalkeycluster/dict.h +++ /dev/null @@ -1,125 +0,0 @@ -/* Hash table implementation. - * - * This file implements in memory hash tables with insert/del/replace/find/ - * get-random-element operations. Hash tables will auto resize if needed - * tables of power of two in size are used, collisions are handled by - * chaining. See the source code for more information... :) - * - * Copyright (c) 2006-2010, Salvatore Sanfilippo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Redis nor the names of its contributors may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __DICT_H -#define __DICT_H - -#define DICT_OK 0 -#define DICT_ERR 1 - -/* Unused arguments generate annoying warnings... */ -#define DICT_NOTUSED(V) ((void)V) - -typedef struct dictEntry { - void *key; - void *val; - struct dictEntry *next; -} dictEntry; - -typedef struct dictType { - unsigned int (*hashFunction)(const void *key); - void *(*keyDup)(void *privdata, const void *key); - void *(*valDup)(void *privdata, const void *obj); - int (*keyCompare)(void *privdata, const void *key1, const void *key2); - void (*keyDestructor)(void *privdata, void *key); - void (*valDestructor)(void *privdata, void *obj); -} dictType; - -typedef struct dict { - dictEntry **table; - dictType *type; - unsigned long size; - unsigned long sizemask; - unsigned long used; - void *privdata; -} dict; - -typedef struct dictIterator { - dict *ht; - int index; - dictEntry *entry, *nextEntry; -} dictIterator; - -/* This is the initial size of every hash table */ -#define DICT_HT_INITIAL_SIZE 4 - -/* ------------------------------- Macros ------------------------------------*/ -#define dictFreeEntryVal(ht, entry) \ - if ((ht)->type->valDestructor) \ - (ht)->type->valDestructor((ht)->privdata, (entry)->val) - -#define dictSetHashVal(ht, entry, _val_) \ - do { \ - if ((ht)->type->valDup) \ - entry->val = (ht)->type->valDup((ht)->privdata, _val_); \ - else \ - entry->val = (_val_); \ - } while (0) - -#define dictFreeEntryKey(ht, entry) \ - if ((ht)->type->keyDestructor) \ - (ht)->type->keyDestructor((ht)->privdata, (entry)->key) - -#define dictSetHashKey(ht, entry, _key_) \ - do { \ - if ((ht)->type->keyDup) \ - entry->key = (ht)->type->keyDup((ht)->privdata, _key_); \ - else \ - entry->key = (_key_); \ - } while (0) - -#define dictCompareHashKeys(ht, key1, key2) \ - (((ht)->type->keyCompare) ? \ - (ht)->type->keyCompare((ht)->privdata, key1, key2) : \ - (key1) == (key2)) - -#define dictHashKey(ht, key) (ht)->type->hashFunction(key) - -#define dictGetEntryKey(he) ((he)->key) -#define dictGetEntryVal(he) ((he)->val) -#define dictSlots(ht) ((ht)->size) -#define dictSize(ht) ((ht)->used) - -/* API */ -unsigned int dictGenHashFunction(const unsigned char *buf, int len); -dict *dictCreate(dictType *type, void *privDataPtr); -int dictExpand(dict *ht, unsigned long size); -int dictAdd(dict *ht, void *key, void *val); -void dictRelease(dict *ht); -dictEntry *dictFind(dict *ht, const void *key); -void dictInitIterator(dictIterator *iter, dict *ht); -dictEntry *dictNext(dictIterator *iter); - -#endif /* __DICT_H */ 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..518f8928 100644 --- a/libvalkeycluster/examples/src/example.c +++ b/libvalkeycluster/examples/src/example.c @@ -1,32 +1,33 @@ -#include #include #include +#include int main(int argc, char **argv) { UNUSED(argc); 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..82cb220e 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", - "SET %s %s", "key", "value"); - if (status != REDIS_OK) { + status = valkeyClusterAsyncCommand(cc, setCallback, (char *)"THE_ID", + "SET %s %s", "key", "value"); + if (status != VALKEY_OK) { printf("error: err=%d errstr=%s\n", cc->err, cc->errstr); } - status = redisClusterAsyncCommand(cc, getCallback, (char *)"THE_ID", - "GET %s", "key"); - if (status != REDIS_OK) { + status = valkeyClusterAsyncCommand(cc, getCallback, (char *)"THE_ID", + "GET %s", "key"); + if (status != VALKEY_OK) { printf("error: err=%d errstr=%s\n", cc->err, cc->errstr); } - status = redisClusterAsyncCommand(cc, setCallback, (char *)"THE_ID", - "SET %s %s", "key2", "value2"); - if (status != REDIS_OK) { + status = valkeyClusterAsyncCommand(cc, setCallback, (char *)"THE_ID", + "SET %s %s", "key2", "value2"); + if (status != VALKEY_OK) { printf("error: err=%d errstr=%s\n", cc->err, cc->errstr); } - status = redisClusterAsyncCommand(cc, getCallback, (char *)"THE_ID", - "GET %s", "key2"); - if (status != REDIS_OK) { + status = valkeyClusterAsyncCommand(cc, getCallback, (char *)"THE_ID", + "GET %s", "key2"); + 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..820a42a2 100644 --- a/libvalkeycluster/examples/src/example_tls.c +++ b/libvalkeycluster/examples/src/example_tls.c @@ -1,9 +1,9 @@ -#include -#include -#include -#include #include #include +#include +#include +#include +#include #define CLUSTER_NODE_TLS "127.0.0.1:7301" @@ -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", - NULL, &ssl_error); + 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,8 @@ 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 +55,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..305ca75e 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/main/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/topics/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/hircluster.h b/libvalkeycluster/hircluster.h deleted file mode 100644 index 4a365380..00000000 --- a/libvalkeycluster/hircluster.h +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright (c) 2015-2017, Ieshen Zheng - * Copyright (c) 2020, Nick - * Copyright (c) 2020-2021, Bjorn Svensson - * Copyright (c) 2021, Red Hat - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Redis nor the names of its contributors may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __HIRCLUSTER_H -#define __HIRCLUSTER_H - -#include "dict.h" -#include -#include - -#define UNUSED(x) (void)(x) - -#define HIREDIS_CLUSTER_MAJOR 0 -#define HIREDIS_CLUSTER_MINOR 13 -#define HIREDIS_CLUSTER_PATCH 0 -#define HIREDIS_CLUSTER_SONAME 0.13 - -#define REDIS_CLUSTER_SLOTS 16384 - -#define REDIS_ROLE_NULL 0 -#define REDIS_ROLE_MASTER 1 -#define REDIS_ROLE_SLAVE 2 - -/* Configuration flags */ -#define HIRCLUSTER_FLAG_NULL 0x0 -/* Flag to enable parsing of slave nodes. Currently not used, but the - information is added to its master node structure. */ -#define HIRCLUSTER_FLAG_ADD_SLAVE 0x1000 -/* Flag to enable parsing of importing/migrating slots for master nodes. - * Only applicable when 'cluster nodes' command is used for route updates. */ -#define HIRCLUSTER_FLAG_ADD_OPENSLOT 0x2000 -/* Flag to enable routing table updates using the command 'cluster slots'. - * Default is the 'cluster nodes' command. */ -#define HIRCLUSTER_FLAG_ROUTE_USE_SLOTS 0x4000 - -/* Events, for redisClusterSetEventCallback() */ -#define HIRCLUSTER_EVENT_SLOTMAP_UPDATED 1 -#define HIRCLUSTER_EVENT_READY 2 -#define HIRCLUSTER_EVENT_FREE_CONTEXT 3 - -/* The non-const connect callback API is not available when: - * - using hiredis prior v.1.1.0; or - * - built on Windows since hiredis_cluster.def can't have conditional definitions. */ -#if !(HIREDIS_MAJOR >= 1 && HIREDIS_MINOR >= 1) || _WIN32 -#define HIRCLUSTER_NO_NONCONST_CONNECT_CB -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -struct dict; -struct hilist; -struct redisClusterAsyncContext; - -typedef int(adapterAttachFn)(redisAsyncContext *, void *); -typedef int(sslInitFn)(redisContext *, void *); -typedef void(redisClusterCallbackFn)(struct redisClusterAsyncContext *, void *, - void *); -typedef struct redisClusterNode { - sds name; - sds addr; - sds host; - uint16_t port; - uint8_t role; - uint8_t pad; - int failure_count; /* consecutive failing attempts in async */ - redisContext *con; - redisAsyncContext *acon; - int64_t lastConnectionAttempt; /* Timestamp */ - struct hilist *slots; - struct hilist *slaves; - struct hiarray *migrating; /* copen_slot[] */ - struct hiarray *importing; /* copen_slot[] */ -} redisClusterNode; - -typedef struct cluster_slot { - uint32_t start; - uint32_t end; - redisClusterNode *node; /* master that this slot region belong to */ -} cluster_slot; - -typedef struct copen_slot { - uint32_t slot_num; /* slot number */ - int migrate; /* migrating or importing? */ - sds remote_name; /* name of node this slot migrating to/importing from */ - redisClusterNode *node; /* master that this slot belong to */ -} copen_slot; - -/* Context for accessing a Redis Cluster */ -typedef struct redisClusterContext { - int err; /* Error flags, 0 when there is no error */ - char errstr[128]; /* String representation of error when applicable */ - - /* Configurations */ - int flags; /* Configuration flags */ - struct timeval *connect_timeout; /* TCP connect timeout */ - struct timeval *command_timeout; /* Receive and send timeout */ - int max_retry_count; /* Allowed retry attempts */ - char *username; /* Authenticate using user */ - char *password; /* Authentication password */ - - struct dict *nodes; /* Known redisClusterNode's */ - uint64_t route_version; /* Increased when the node lookup table changes */ - redisClusterNode **table; /* redisClusterNode lookup table */ - - struct hilist *requests; /* Outstanding commands (Pipelining) */ - - int retry_count; /* Current number of failing attempts */ - int need_update_route; /* Indicator for redisClusterReset() (Pipel.) */ - - void *ssl; /* Pointer to a redisSSLContext when using SSL/TLS. */ - sslInitFn *ssl_init_fn; /* Func ptr for SSL context initiation */ - - void (*on_connect)(const struct redisContext *c, int status); - void (*event_callback)(const struct redisClusterContext *cc, int event, - void *privdata); - void *event_privdata; - -} redisClusterContext; - -/* Context for accessing a Redis Cluster asynchronously */ -typedef struct redisClusterAsyncContext { - redisClusterContext *cc; - - int err; /* Error flags, 0 when there is no error */ - char errstr[128]; /* String representation of error when applicable */ - - int64_t lastSlotmapUpdateAttempt; /* Timestamp */ - - void *adapter; /* Adapter to the async event library */ - adapterAttachFn *attach_fn; /* Func ptr for attaching the async library */ - - /* Called when either the connection is terminated due to an error or per - * user request. The status is set accordingly (REDIS_OK, REDIS_ERR). */ - redisDisconnectCallback *onDisconnect; - - /* Called when the first write event was received. */ - redisConnectCallback *onConnect; -#ifndef HIRCLUSTER_NO_NONCONST_CONNECT_CB - redisConnectCallbackNC *onConnectNC; -#endif - -} redisClusterAsyncContext; - -typedef struct redisClusterNodeIterator { - redisClusterContext *cc; - uint64_t route_version; - int retries_left; - dictIterator di; -} redisClusterNodeIterator; - -/* - * Synchronous API - */ - -redisClusterContext *redisClusterConnect(const char *addrs, int flags); -redisClusterContext *redisClusterConnectWithTimeout(const char *addrs, - const struct timeval tv, - int flags); -int redisClusterConnect2(redisClusterContext *cc); - -redisClusterContext *redisClusterContextInit(void); -void redisClusterFree(redisClusterContext *cc); - -/* Configuration options */ -int redisClusterSetOptionAddNode(redisClusterContext *cc, const char *addr); -int redisClusterSetOptionAddNodes(redisClusterContext *cc, const char *addrs); -/* Deprecated function, option has no effect. */ -int redisClusterSetOptionConnectBlock(redisClusterContext *cc); -/* Deprecated function, option has no effect. */ -int redisClusterSetOptionConnectNonBlock(redisClusterContext *cc); -int redisClusterSetOptionUsername(redisClusterContext *cc, - const char *username); -int redisClusterSetOptionPassword(redisClusterContext *cc, - const char *password); -int redisClusterSetOptionParseSlaves(redisClusterContext *cc); -int redisClusterSetOptionParseOpenSlots(redisClusterContext *cc); -int redisClusterSetOptionRouteUseSlots(redisClusterContext *cc); -int redisClusterSetOptionConnectTimeout(redisClusterContext *cc, - const struct timeval tv); -int redisClusterSetOptionTimeout(redisClusterContext *cc, - const struct timeval tv); -int redisClusterSetOptionMaxRetry(redisClusterContext *cc, int max_retry_count); -/* Deprecated function, replaced with redisClusterSetOptionMaxRetry() */ -void redisClusterSetMaxRedirect(redisClusterContext *cc, - int max_redirect_count); -/* A hook for connect and reconnect attempts, e.g. for applying additional - * socket options. This is called just after connect, before TLS handshake and - * Redis authentication. - * - * On successful connection, `status` is set to `REDIS_OK` and the file - * descriptor can be accessed as `c->fd` to apply socket options. - * - * On failed connection attempt, this callback is called with `status` set to - * `REDIS_ERR`. The `err` field in the `redisContext` can be used to find out - * the cause of the error. */ -int redisClusterSetConnectCallback(redisClusterContext *cc, - void(fn)(const redisContext *c, int status)); - -/* A hook for events. */ -int redisClusterSetEventCallback(redisClusterContext *cc, - void(fn)(const redisClusterContext *cc, - int event, void *privdata), - void *privdata); - -/* Blocking - * The following functions will block for a reply, or return NULL if there was - * an error in performing the command. - */ - -/* Variadic commands (like printf) */ -void *redisClusterCommand(redisClusterContext *cc, const char *format, ...); -void *redisClusterCommandToNode(redisClusterContext *cc, redisClusterNode *node, - const char *format, ...); -/* Variadic using va_list */ -void *redisClustervCommand(redisClusterContext *cc, const char *format, - va_list ap); -/* Using argc and argv */ -void *redisClusterCommandArgv(redisClusterContext *cc, int argc, - const char **argv, const size_t *argvlen); -/* Send a Redis protocol encoded string */ -void *redisClusterFormattedCommand(redisClusterContext *cc, char *cmd, int len); - -/* Pipelining - * The following functions will write a command to the output buffer. - * A call to `redisClusterGetReply()` will flush all commands in the output - * buffer and read until it has a reply from the first command in the buffer. - */ - -/* Variadic commands (like printf) */ -int redisClusterAppendCommand(redisClusterContext *cc, const char *format, ...); -int redisClusterAppendCommandToNode(redisClusterContext *cc, - redisClusterNode *node, const char *format, - ...); -/* Variadic using va_list */ -int redisClustervAppendCommand(redisClusterContext *cc, const char *format, - va_list ap); -/* Using argc and argv */ -int redisClusterAppendCommandArgv(redisClusterContext *cc, int argc, - const char **argv, const size_t *argvlen); -/* Use a Redis protocol encoded string as command */ -int redisClusterAppendFormattedCommand(redisClusterContext *cc, char *cmd, - int len); -/* Flush output buffer and return first reply */ -int redisClusterGetReply(redisClusterContext *cc, void **reply); - -/* Reset context after a performed pipelining */ -void redisClusterReset(redisClusterContext *cc); - -/* Update the slotmap by querying any node. */ -int redisClusterUpdateSlotmap(redisClusterContext *cc); - -/* Internal functions */ -redisContext *ctx_get_by_node(redisClusterContext *cc, redisClusterNode *node); -struct dict *parse_cluster_nodes(redisClusterContext *cc, char *str, - int str_len, int flags); -struct dict *parse_cluster_slots(redisClusterContext *cc, redisReply *reply, - int flags); - -/* - * Asynchronous API - */ - -redisClusterAsyncContext *redisClusterAsyncContextInit(void); -void redisClusterAsyncFree(redisClusterAsyncContext *acc); - -int redisClusterAsyncSetConnectCallback(redisClusterAsyncContext *acc, - redisConnectCallback *fn); -#ifndef HIRCLUSTER_NO_NONCONST_CONNECT_CB -int redisClusterAsyncSetConnectCallbackNC(redisClusterAsyncContext *acc, - redisConnectCallbackNC *fn); -#endif -int redisClusterAsyncSetDisconnectCallback(redisClusterAsyncContext *acc, - redisDisconnectCallback *fn); - -/* Connect and update slotmap, will block until complete. */ -redisClusterAsyncContext *redisClusterAsyncConnect(const char *addrs, - int flags); -/* Connect and update slotmap asynchronously using configured event engine. */ -int redisClusterAsyncConnect2(redisClusterAsyncContext *acc); -void redisClusterAsyncDisconnect(redisClusterAsyncContext *acc); - -/* Commands */ -int redisClusterAsyncCommand(redisClusterAsyncContext *acc, - redisClusterCallbackFn *fn, void *privdata, - const char *format, ...); -int redisClusterAsyncCommandToNode(redisClusterAsyncContext *acc, - redisClusterNode *node, - redisClusterCallbackFn *fn, void *privdata, - const char *format, ...); -int redisClustervAsyncCommand(redisClusterAsyncContext *acc, - redisClusterCallbackFn *fn, void *privdata, - const char *format, va_list ap); -int redisClusterAsyncCommandArgv(redisClusterAsyncContext *acc, - redisClusterCallbackFn *fn, void *privdata, - int argc, const char **argv, - const size_t *argvlen); -int redisClusterAsyncCommandArgvToNode(redisClusterAsyncContext *acc, - redisClusterNode *node, - redisClusterCallbackFn *fn, - void *privdata, int argc, - const char **argv, - const size_t *argvlen); - -/* Use a Redis protocol encoded string as command */ -int redisClusterAsyncFormattedCommand(redisClusterAsyncContext *acc, - redisClusterCallbackFn *fn, - void *privdata, char *cmd, int len); -int redisClusterAsyncFormattedCommandToNode(redisClusterAsyncContext *acc, - redisClusterNode *node, - redisClusterCallbackFn *fn, - void *privdata, char *cmd, int len); - -/* Internal functions */ -redisAsyncContext *actx_get_by_node(redisClusterAsyncContext *acc, - redisClusterNode *node); - -/* Cluster node iterator functions */ -void redisClusterInitNodeIterator(redisClusterNodeIterator *iter, - redisClusterContext *cc); -redisClusterNode *redisClusterNodeNext(redisClusterNodeIterator *iter); - -/* Helper functions */ -unsigned int redisClusterGetSlotByKey(char *key); -redisClusterNode *redisClusterGetNodeByKey(redisClusterContext *cc, char *key); - -/* Old names of renamed functions and types, kept for backward compatibility. */ -#ifndef HIRCLUSTER_NO_OLD_NAMES -#define cluster_update_route redisClusterUpdateSlotmap -#define initNodeIterator redisClusterInitNodeIterator -#define nodeNext redisClusterNodeNext -#define redisClusterConnectNonBlock redisClusterConnect -typedef struct redisClusterNode cluster_node; -typedef struct redisClusterNodeIterator nodeIterator; -#endif - -#ifdef __cplusplus -} -#endif - -#endif 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..8f19589a 100644 --- a/libvalkeycluster/tests/clusterclient_async.c +++ b/libvalkeycluster/tests/clusterclient_async.c @@ -34,8 +34,8 @@ */ #include "adapters/libevent.h" -#include "hircluster.h" #include "test_utils.h" +#include "valkeycluster.h" #include #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..e0ed7618 100644 --- a/libvalkeycluster/tests/clusterclient_reconnect_async.c +++ b/libvalkeycluster/tests/clusterclient_reconnect_async.c @@ -1,35 +1,36 @@ /* - * 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 "test_utils.h" +#include "valkeycluster.h" #include #include #include #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 +40,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 +64,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 +77,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, - NULL, command); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + int status = valkeyClusterAsyncCommandToNode(acc, node, replyCallback, + NULL, command); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); } else { // disconnect if nothing is left to read from stdin - redisClusterAsyncDisconnect(acc); + valkeyClusterAsyncDisconnect(acc); } } @@ -96,22 +97,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..27eae289 100644 --- a/libvalkeycluster/tests/ct_async.c +++ b/libvalkeycluster/tests/ct_async.c @@ -1,110 +1,105 @@ #include "adapters/libevent.h" -#include "hircluster.h" #include "test_utils.h" +#include "valkeycluster.h" #include #include #include #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", - "SET key12345 value"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + status = valkeyClusterAsyncCommand(acc, setCallback, (char *)"ID", + "SET key12345 value"); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); /* This command will trigger a disconnect in its reply callback. */ - status = redisClusterAsyncCommand(acc, getCallback, (char *)"ID", - "GET key12345"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + status = valkeyClusterAsyncCommand(acc, getCallback, (char *)"ID", + "GET key12345"); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); - status = redisClusterAsyncCommand(acc, setCallback, (char *)"ID", - "SET key23456 value2"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + status = valkeyClusterAsyncCommand(acc, setCallback, (char *)"ID", + "SET key23456 value2"); + ASSERT_MSG(status == VALKEY_OK, acc->errstr); - status = redisClusterAsyncCommand(acc, getCallback, (char *)"ID", - "GET key23456"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + status = valkeyClusterAsyncCommand(acc, getCallback, (char *)"ID", + "GET key23456"); + 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..fb1609f4 100644 --- a/libvalkeycluster/tests/ct_async_glib.c +++ b/libvalkeycluster/tests/ct_async_glib.c @@ -1,35 +1,35 @@ #include "adapters/glib.h" -#include "hircluster.h" #include "test_utils.h" +#include "valkeycluster.h" #include #define CLUSTER_NODE "127.0.0.1:7000" 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..27559e5b 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 "test_utils.h" +#include "valkeycluster.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", - "SET key value"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + status = valkeyClusterAsyncCommand(acc, setCallback, (char *)"ID", + "SET key value"); + 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..8b9e9148 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 "test_utils.h" +#include "valkeycluster.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", - "SET key value"); - ASSERT_MSG(status == REDIS_OK, acc->errstr); + status = valkeyClusterAsyncCommand(acc, setCallback, (char *)"ID", + "SET key value"); + 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..5281f7f6 100644 --- a/libvalkeycluster/tests/ct_commands.c +++ b/libvalkeycluster/tests/ct_commands.c @@ -1,5 +1,5 @@ -#include "hircluster.h" #include "test_utils.h" +#include "valkeycluster.h" #include "win32.h" #include #include @@ -8,91 +8,92 @@ #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 +101,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"); + reply = (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 +169,23 @@ void test_hset_hget_hdel_hexists(redisClusterContext *cc) { // Command layout: // eval