From bb3475e8eb379ee18f3d8f37caa8040b852a6213 Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Sat, 23 Mar 2024 01:21:46 +0100 Subject: all: rename redis -> redict symbols and comments Signed-off-by: Anna (navi) Figueiredo Gomes --- CMakeLists.txt | 18 +- Makefile | 26 +- adapters/ae.h | 74 +- adapters/glib.h | 98 +-- adapters/ivykis.h | 74 +- adapters/libev.h | 94 +-- adapters/libevent.h | 106 +-- adapters/libhv.h | 80 +- adapters/libsdevent.h | 104 +-- adapters/libuv.h | 90 +-- adapters/macosx.h | 110 +-- adapters/poll.h | 102 +-- adapters/qt.h | 64 +- adapters/redictmoduleapi.h | 122 +-- alloc.c | 24 +- alloc.h | 28 +- appveyor.yml | 2 +- async.c | 516 ++++++------- async.h | 100 +-- async_private.h | 24 +- examples/example-ae.c | 26 +- examples/example-glib.c | 28 +- examples/example-ivykis.c | 26 +- examples/example-libev.c | 26 +- examples/example-libevent-ssl.c | 40 +- examples/example-libevent.c | 30 +- examples/example-libhv.c | 36 +- examples/example-libsdevent.c | 36 +- examples/example-libuv.c | 34 +- examples/example-macosx.c | 26 +- examples/example-poll.c | 28 +- examples/example-push.c | 56 +- examples/example-qt.cpp | 12 +- examples/example-qt.h | 12 +- examples/example-redictmoduleapi.c | 58 +- examples/example-ssl.c | 52 +- examples/example.c | 44 +- fmacros.h | 4 +- fuzzing/format_command_fuzzer.c | 2 +- hiredict-config.cmake.in | 12 +- hiredict.c | 590 +++++++-------- hiredict.h | 260 +++---- hiredict.pc.in | 8 +- hiredict_ssl-config.cmake.in | 12 +- hiredict_ssl.h | 78 +- hiredict_ssl.pc.in | 10 +- net.c | 340 ++++----- net.h | 26 +- read.c | 306 ++++---- read.h | 104 +-- sds.h | 2 +- sockcompat.c | 4 +- sockcompat.h | 6 +- ssl.c | 218 +++--- test.c | 1440 ++++++++++++++++++------------------ 55 files changed, 2923 insertions(+), 2925 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 195934f..dd385f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,11 +13,11 @@ MACRO(getVersionBit name) STRING(REGEX REPLACE ${VERSION_REGEX} "\\1" ${name} "${VERSION_BIT}") ENDMACRO(getVersionBit) -getVersionBit(HIREDIS_MAJOR) -getVersionBit(HIREDIS_MINOR) -getVersionBit(HIREDIS_PATCH) -getVersionBit(HIREDIS_SONAME) -SET(VERSION "${HIREDIS_MAJOR}.${HIREDIS_MINOR}.${HIREDIS_PATCH}") +getVersionBit(HIREDICT_MAJOR) +getVersionBit(HIREDICT_MINOR) +getVersionBit(HIREDICT_PATCH) +getVersionBit(HIREDICT_SONAME) +SET(VERSION "${HIREDICT_MAJOR}.${HIREDICT_MINOR}.${HIREDICT_PATCH}") MESSAGE("Detected version: ${VERSION}") PROJECT(hiredict LANGUAGES "C" VERSION "${VERSION}") @@ -59,7 +59,7 @@ set_target_properties(hiredict PROPERTIES EXPORT_NAME ${hiredict_export_name}) SET_TARGET_PROPERTIES(hiredict PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE - VERSION "${HIREDIS_SONAME}") + VERSION "${HIREDICT_SONAME}") IF(MSVC) SET_TARGET_PROPERTIES(hiredict PROPERTIES COMPILE_FLAGS /Z7) @@ -174,7 +174,7 @@ IF(ENABLE_SSL) SET_TARGET_PROPERTIES(hiredict_ssl PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE - VERSION "${HIREDIS_SONAME}") + VERSION "${HIREDICT_SONAME}") IF(MSVC) SET_TARGET_PROPERTIES(hiredict_ssl PROPERTIES COMPILE_FLAGS /Z7) @@ -231,11 +231,11 @@ IF(NOT DISABLE_TESTS) ADD_EXECUTABLE(hiredict-test test.c) TARGET_LINK_LIBRARIES(hiredict-test hiredict) IF(ENABLE_SSL_TESTS) - ADD_DEFINITIONS(-DHIREDIS_TEST_SSL=1) + ADD_DEFINITIONS(-DHIREDICT_TEST_SSL=1) TARGET_LINK_LIBRARIES(hiredict-test hiredict_ssl) ENDIF() IF(ENABLE_ASYNC_TESTS) - ADD_DEFINITIONS(-DHIREDIS_TEST_ASYNC=1) + ADD_DEFINITIONS(-DHIREDICT_TEST_ASYNC=1) TARGET_LINK_LIBRARIES(hiredict-test event) ENDIF() ADD_TEST(NAME hiredict-test diff --git a/Makefile b/Makefile index 2b12491..6923482 100644 --- a/Makefile +++ b/Makefile @@ -15,10 +15,10 @@ TESTS=hiredict-test LIBNAME=libhiredict PKGCONFNAME=hiredict.pc -HIREDIS_MAJOR=$(shell grep HIREDIS_MAJOR hiredict.h | awk '{print $$3}') -HIREDIS_MINOR=$(shell grep HIREDIS_MINOR hiredict.h | awk '{print $$3}') -HIREDIS_PATCH=$(shell grep HIREDIS_PATCH hiredict.h | awk '{print $$3}') -HIREDIS_SONAME=$(shell grep HIREDIS_SONAME hiredict.h | awk '{print $$3}') +HIREDICT_MAJOR=$(shell grep HIREDICT_MAJOR hiredict.h | awk '{print $$3}') +HIREDICT_MINOR=$(shell grep HIREDICT_MINOR hiredict.h | awk '{print $$3}') +HIREDICT_PATCH=$(shell grep HIREDICT_PATCH hiredict.h | awk '{print $$3}') +HIREDICT_SONAME=$(shell grep HIREDICT_SONAME hiredict.h | awk '{print $$3}') # Installation related variables and target PREFIX?=/usr/local @@ -56,8 +56,8 @@ REAL_LDFLAGS=$(LDFLAGS) DYLIBSUFFIX=so STLIBSUFFIX=a -DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_SONAME) -DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR) +DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDICT_SONAME) +DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDICT_MAJOR) DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX) DYLIB_MAKE_CMD=$(CC) $(PLATFORM_FLAGS) -shared -Wl,-soname,$(DYLIB_MINOR_NAME) @@ -69,8 +69,8 @@ SSL_OBJ=ssl.o SSL_LIBNAME=libhiredict_ssl SSL_PKGCONFNAME=hiredict_ssl.pc SSL_INSTALLNAME=install-ssl -SSL_DYLIB_MINOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_SONAME) -SSL_DYLIB_MAJOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR) +SSL_DYLIB_MINOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(HIREDICT_SONAME) +SSL_DYLIB_MAJOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(HIREDICT_MAJOR) SSL_DYLIBNAME=$(SSL_LIBNAME).$(DYLIBSUFFIX) SSL_STLIBNAME=$(SSL_LIBNAME).$(STLIBSUFFIX) SSL_DYLIB_MAKE_CMD=$(CC) $(PLATFORM_FLAGS) -shared -Wl,-soname,$(SSL_DYLIB_MINOR_NAME) @@ -78,7 +78,7 @@ SSL_DYLIB_MAKE_CMD=$(CC) $(PLATFORM_FLAGS) -shared -Wl,-soname,$(SSL_DYLIB_MINOR USE_SSL?=0 ifeq ($(USE_SSL),1) # This is required for test.c only - CFLAGS+=-DHIREDIS_TEST_SSL + CFLAGS+=-DHIREDICT_TEST_SSL EXAMPLES+=hiredict-example-ssl hiredict-example-libevent-ssl SSL_STLIB=$(SSL_STLIBNAME) SSL_DYLIB=$(SSL_DYLIBNAME) @@ -98,7 +98,7 @@ uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') # This is required for test.c only ifeq ($(TEST_ASYNC),1) - export CFLAGS+=-DHIREDIS_TEST_ASYNC + export CFLAGS+=-DHIREDICT_TEST_ASYNC endif ifeq ($(USE_SSL),1) @@ -146,7 +146,7 @@ ifeq ($(uname_S),SunOS) endif ifeq ($(uname_S),Darwin) DYLIBSUFFIX=dylib - DYLIB_MINOR_NAME=$(LIBNAME).$(HIREDIS_SONAME).$(DYLIBSUFFIX) + DYLIB_MINOR_NAME=$(LIBNAME).$(HIREDICT_SONAME).$(DYLIBSUFFIX) DYLIB_MAKE_CMD=$(CC) -dynamiclib -Wl,-install_name,$(PREFIX)/$(LIBRARY_PATH)/$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS) SSL_DYLIB_MAKE_CMD=$(CC) -dynamiclib -Wl,-install_name,$(PREFIX)/$(LIBRARY_PATH)/$(SSL_DYLIB_MINOR_NAME) -o $(SSL_DYLIBNAME) $(LDFLAGS) $(SSL_LDFLAGS) DYLIB_PLUGIN=-Wl,-undefined -Wl,dynamic_lookup @@ -297,7 +297,7 @@ $(PKGCONFNAME): hiredict.h @echo >> $@ @echo Name: hiredict >> $@ @echo Description: Minimalistic C client library for Redis. >> $@ - @echo Version: $(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(HIREDIS_PATCH) >> $@ + @echo Version: $(HIREDICT_MAJOR).$(HIREDICT_MINOR).$(HIREDICT_PATCH) >> $@ @echo Libs: -L\$${libdir} -lhiredict >> $@ @echo Cflags: -I\$${pkgincludedir} -I\$${includedir} -D_FILE_OFFSET_BITS=64 >> $@ @@ -311,7 +311,7 @@ $(SSL_PKGCONFNAME): hiredict_ssl.h @echo >> $@ @echo Name: hiredict_ssl >> $@ @echo Description: SSL Support for hiredict. >> $@ - @echo Version: $(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(HIREDIS_PATCH) >> $@ + @echo Version: $(HIREDICT_MAJOR).$(HIREDICT_MINOR).$(HIREDICT_PATCH) >> $@ @echo Requires: hiredict >> $@ @echo Libs: -L\$${libdir} -lhiredict_ssl >> $@ @echo Libs.private: -lssl -lcrypto >> $@ diff --git a/adapters/ae.h b/adapters/ae.h index 44db8ee..1edcd0e 100644 --- a/adapters/ae.h +++ b/adapters/ae.h @@ -9,45 +9,45 @@ * */ -#ifndef __HIREDIS_AE_H__ -#define __HIREDIS_AE_H__ +#ifndef __HIREDICT_AE_H__ +#define __HIREDICT_AE_H__ #include #include #include "../hiredict.h" #include "../async.h" -typedef struct redisAeEvents { - redisAsyncContext *context; +typedef struct redictAeEvents { + redictAsyncContext *context; aeEventLoop *loop; int fd; int reading, writing; -} redisAeEvents; +} redictAeEvents; -static void redisAeReadEvent(aeEventLoop *el, int fd, void *privdata, int mask) { +static void redictAeReadEvent(aeEventLoop *el, int fd, void *privdata, int mask) { ((void)el); ((void)fd); ((void)mask); - redisAeEvents *e = (redisAeEvents*)privdata; - redisAsyncHandleRead(e->context); + redictAeEvents *e = (redictAeEvents*)privdata; + redictAsyncHandleRead(e->context); } -static void redisAeWriteEvent(aeEventLoop *el, int fd, void *privdata, int mask) { +static void redictAeWriteEvent(aeEventLoop *el, int fd, void *privdata, int mask) { ((void)el); ((void)fd); ((void)mask); - redisAeEvents *e = (redisAeEvents*)privdata; - redisAsyncHandleWrite(e->context); + redictAeEvents *e = (redictAeEvents*)privdata; + redictAsyncHandleWrite(e->context); } -static void redisAeAddRead(void *privdata) { - redisAeEvents *e = (redisAeEvents*)privdata; +static void redictAeAddRead(void *privdata) { + redictAeEvents *e = (redictAeEvents*)privdata; aeEventLoop *loop = e->loop; if (!e->reading) { e->reading = 1; - aeCreateFileEvent(loop,e->fd,AE_READABLE,redisAeReadEvent,e); + aeCreateFileEvent(loop,e->fd,AE_READABLE,redictAeReadEvent,e); } } -static void redisAeDelRead(void *privdata) { - redisAeEvents *e = (redisAeEvents*)privdata; +static void redictAeDelRead(void *privdata) { + redictAeEvents *e = (redictAeEvents*)privdata; aeEventLoop *loop = e->loop; if (e->reading) { e->reading = 0; @@ -55,17 +55,17 @@ static void redisAeDelRead(void *privdata) { } } -static void redisAeAddWrite(void *privdata) { - redisAeEvents *e = (redisAeEvents*)privdata; +static void redictAeAddWrite(void *privdata) { + redictAeEvents *e = (redictAeEvents*)privdata; aeEventLoop *loop = e->loop; if (!e->writing) { e->writing = 1; - aeCreateFileEvent(loop,e->fd,AE_WRITABLE,redisAeWriteEvent,e); + aeCreateFileEvent(loop,e->fd,AE_WRITABLE,redictAeWriteEvent,e); } } -static void redisAeDelWrite(void *privdata) { - redisAeEvents *e = (redisAeEvents*)privdata; +static void redictAeDelWrite(void *privdata) { + redictAeEvents *e = (redictAeEvents*)privdata; aeEventLoop *loop = e->loop; if (e->writing) { e->writing = 0; @@ -73,25 +73,25 @@ static void redisAeDelWrite(void *privdata) { } } -static void redisAeCleanup(void *privdata) { - redisAeEvents *e = (redisAeEvents*)privdata; - redisAeDelRead(privdata); - redisAeDelWrite(privdata); +static void redictAeCleanup(void *privdata) { + redictAeEvents *e = (redictAeEvents*)privdata; + redictAeDelRead(privdata); + redictAeDelWrite(privdata); hi_free(e); } -static int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) { - redisContext *c = &(ac->c); - redisAeEvents *e; +static int redictAeAttach(aeEventLoop *loop, redictAsyncContext *ac) { + redictContext *c = &(ac->c); + redictAeEvents *e; /* Nothing should be attached when something is already attached */ if (ac->ev.data != NULL) - return REDIS_ERR; + return REDICT_ERR; /* Create container for context and r/w events */ - e = (redisAeEvents*)hi_malloc(sizeof(*e)); + e = (redictAeEvents*)hi_malloc(sizeof(*e)); if (e == NULL) - return REDIS_ERR; + return REDICT_ERR; e->context = ac; e->loop = loop; @@ -99,13 +99,13 @@ static int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) { e->reading = e->writing = 0; /* Register functions to start/stop listening for events */ - ac->ev.addRead = redisAeAddRead; - ac->ev.delRead = redisAeDelRead; - ac->ev.addWrite = redisAeAddWrite; - ac->ev.delWrite = redisAeDelWrite; - ac->ev.cleanup = redisAeCleanup; + ac->ev.addRead = redictAeAddRead; + ac->ev.delRead = redictAeDelRead; + ac->ev.addWrite = redictAeAddWrite; + ac->ev.delWrite = redictAeDelWrite; + ac->ev.cleanup = redictAeCleanup; ac->ev.data = e; - return REDIS_OK; + return REDICT_OK; } #endif diff --git a/adapters/glib.h b/adapters/glib.h index f3143ed..84490c8 100644 --- a/adapters/glib.h +++ b/adapters/glib.h @@ -9,8 +9,8 @@ * */ -#ifndef __HIREDIS_GLIB_H__ -#define __HIREDIS_GLIB_H__ +#ifndef __HIREDICT_GLIB_H__ +#define __HIREDICT_GLIB_H__ #include @@ -20,55 +20,55 @@ typedef struct { GSource source; - redisAsyncContext *ac; + redictAsyncContext *ac; GPollFD poll_fd; -} RedisSource; +} RedictSource; static void -redis_source_add_read (gpointer data) +redict_source_add_read (gpointer data) { - RedisSource *source = (RedisSource *)data; + RedictSource *source = (RedictSource *)data; g_return_if_fail(source); source->poll_fd.events |= G_IO_IN; g_main_context_wakeup(g_source_get_context((GSource *)data)); } static void -redis_source_del_read (gpointer data) +redict_source_del_read (gpointer data) { - RedisSource *source = (RedisSource *)data; + RedictSource *source = (RedictSource *)data; g_return_if_fail(source); source->poll_fd.events &= ~G_IO_IN; g_main_context_wakeup(g_source_get_context((GSource *)data)); } static void -redis_source_add_write (gpointer data) +redict_source_add_write (gpointer data) { - RedisSource *source = (RedisSource *)data; + RedictSource *source = (RedictSource *)data; g_return_if_fail(source); source->poll_fd.events |= G_IO_OUT; g_main_context_wakeup(g_source_get_context((GSource *)data)); } static void -redis_source_del_write (gpointer data) +redict_source_del_write (gpointer data) { - RedisSource *source = (RedisSource *)data; + RedictSource *source = (RedictSource *)data; g_return_if_fail(source); source->poll_fd.events &= ~G_IO_OUT; g_main_context_wakeup(g_source_get_context((GSource *)data)); } static void -redis_source_cleanup (gpointer data) +redict_source_cleanup (gpointer data) { - RedisSource *source = (RedisSource *)data; + RedictSource *source = (RedictSource *)data; g_return_if_fail(source); - redis_source_del_read(source); - redis_source_del_write(source); + redict_source_del_read(source); + redict_source_del_write(source); /* * It is not our responsibility to remove ourself from the * current main loop. However, we will remove the GPollFD. @@ -80,36 +80,36 @@ redis_source_cleanup (gpointer data) } static gboolean -redis_source_prepare (GSource *source, +redict_source_prepare (GSource *source, gint *timeout_) { - RedisSource *redis = (RedisSource *)source; + RedictSource *redict = (RedictSource *)source; *timeout_ = -1; - return !!(redis->poll_fd.events & redis->poll_fd.revents); + return !!(redict->poll_fd.events & redict->poll_fd.revents); } static gboolean -redis_source_check (GSource *source) +redict_source_check (GSource *source) { - RedisSource *redis = (RedisSource *)source; - return !!(redis->poll_fd.events & redis->poll_fd.revents); + RedictSource *redict = (RedictSource *)source; + return !!(redict->poll_fd.events & redict->poll_fd.revents); } static gboolean -redis_source_dispatch (GSource *source, +redict_source_dispatch (GSource *source, GSourceFunc callback, gpointer user_data) { - RedisSource *redis = (RedisSource *)source; + RedictSource *redict = (RedictSource *)source; - if ((redis->poll_fd.revents & G_IO_OUT)) { - redisAsyncHandleWrite(redis->ac); - redis->poll_fd.revents &= ~G_IO_OUT; + if ((redict->poll_fd.revents & G_IO_OUT)) { + redictAsyncHandleWrite(redict->ac); + redict->poll_fd.revents &= ~G_IO_OUT; } - if ((redis->poll_fd.revents & G_IO_IN)) { - redisAsyncHandleRead(redis->ac); - redis->poll_fd.revents &= ~G_IO_IN; + if ((redict->poll_fd.revents & G_IO_IN)) { + redictAsyncHandleRead(redict->ac); + redict->poll_fd.revents &= ~G_IO_IN; } if (callback) { @@ -120,31 +120,31 @@ redis_source_dispatch (GSource *source, } static void -redis_source_finalize (GSource *source) +redict_source_finalize (GSource *source) { - RedisSource *redis = (RedisSource *)source; + RedictSource *redict = (RedictSource *)source; - if (redis->poll_fd.fd >= 0) { - g_source_remove_poll(source, &redis->poll_fd); - redis->poll_fd.fd = -1; + if (redict->poll_fd.fd >= 0) { + g_source_remove_poll(source, &redict->poll_fd); + redict->poll_fd.fd = -1; } } static GSource * -redis_source_new (redisAsyncContext *ac) +redict_source_new (redictAsyncContext *ac) { static GSourceFuncs source_funcs = { - .prepare = redis_source_prepare, - .check = redis_source_check, - .dispatch = redis_source_dispatch, - .finalize = redis_source_finalize, + .prepare = redict_source_prepare, + .check = redict_source_check, + .dispatch = redict_source_dispatch, + .finalize = redict_source_finalize, }; - redisContext *c = &ac->c; - RedisSource *source; + redictContext *c = &ac->c; + RedictSource *source; g_return_val_if_fail(ac != NULL, NULL); - source = (RedisSource *)g_source_new(&source_funcs, sizeof *source); + source = (RedictSource *)g_source_new(&source_funcs, sizeof *source); if (source == NULL) return NULL; @@ -154,14 +154,14 @@ redis_source_new (redisAsyncContext *ac) source->poll_fd.revents = 0; g_source_add_poll((GSource *)source, &source->poll_fd); - ac->ev.addRead = redis_source_add_read; - ac->ev.delRead = redis_source_del_read; - ac->ev.addWrite = redis_source_add_write; - ac->ev.delWrite = redis_source_del_write; - ac->ev.cleanup = redis_source_cleanup; + ac->ev.addRead = redict_source_add_read; + ac->ev.delRead = redict_source_del_read; + ac->ev.addWrite = redict_source_add_write; + ac->ev.delWrite = redict_source_del_write; + ac->ev.cleanup = redict_source_cleanup; ac->ev.data = source; return (GSource *)source; } -#endif /* __HIREDIS_GLIB_H__ */ +#endif /* __HIREDICT_GLIB_H__ */ diff --git a/adapters/ivykis.h b/adapters/ivykis.h index 544723d..a8468d8 100644 --- a/adapters/ivykis.h +++ b/adapters/ivykis.h @@ -9,87 +9,87 @@ * */ -#ifndef __HIREDIS_IVYKIS_H__ -#define __HIREDIS_IVYKIS_H__ +#ifndef __HIREDICT_IVYKIS_H__ +#define __HIREDICT_IVYKIS_H__ #include #include "../hiredict.h" #include "../async.h" -typedef struct redisIvykisEvents { - redisAsyncContext *context; +typedef struct redictIvykisEvents { + redictAsyncContext *context; struct iv_fd fd; -} redisIvykisEvents; +} redictIvykisEvents; -static void redisIvykisReadEvent(void *arg) { - redisAsyncContext *context = (redisAsyncContext *)arg; - redisAsyncHandleRead(context); +static void redictIvykisReadEvent(void *arg) { + redictAsyncContext *context = (redictAsyncContext *)arg; + redictAsyncHandleRead(context); } -static void redisIvykisWriteEvent(void *arg) { - redisAsyncContext *context = (redisAsyncContext *)arg; - redisAsyncHandleWrite(context); +static void redictIvykisWriteEvent(void *arg) { + redictAsyncContext *context = (redictAsyncContext *)arg; + redictAsyncHandleWrite(context); } -static void redisIvykisAddRead(void *privdata) { - redisIvykisEvents *e = (redisIvykisEvents*)privdata; - iv_fd_set_handler_in(&e->fd, redisIvykisReadEvent); +static void redictIvykisAddRead(void *privdata) { + redictIvykisEvents *e = (redictIvykisEvents*)privdata; + iv_fd_set_handler_in(&e->fd, redictIvykisReadEvent); } -static void redisIvykisDelRead(void *privdata) { - redisIvykisEvents *e = (redisIvykisEvents*)privdata; +static void redictIvykisDelRead(void *privdata) { + redictIvykisEvents *e = (redictIvykisEvents*)privdata; iv_fd_set_handler_in(&e->fd, NULL); } -static void redisIvykisAddWrite(void *privdata) { - redisIvykisEvents *e = (redisIvykisEvents*)privdata; - iv_fd_set_handler_out(&e->fd, redisIvykisWriteEvent); +static void redictIvykisAddWrite(void *privdata) { + redictIvykisEvents *e = (redictIvykisEvents*)privdata; + iv_fd_set_handler_out(&e->fd, redictIvykisWriteEvent); } -static void redisIvykisDelWrite(void *privdata) { - redisIvykisEvents *e = (redisIvykisEvents*)privdata; +static void redictIvykisDelWrite(void *privdata) { + redictIvykisEvents *e = (redictIvykisEvents*)privdata; iv_fd_set_handler_out(&e->fd, NULL); } -static void redisIvykisCleanup(void *privdata) { - redisIvykisEvents *e = (redisIvykisEvents*)privdata; +static void redictIvykisCleanup(void *privdata) { + redictIvykisEvents *e = (redictIvykisEvents*)privdata; iv_fd_unregister(&e->fd); hi_free(e); } -static int redisIvykisAttach(redisAsyncContext *ac) { - redisContext *c = &(ac->c); - redisIvykisEvents *e; +static int redictIvykisAttach(redictAsyncContext *ac) { + redictContext *c = &(ac->c); + redictIvykisEvents *e; /* Nothing should be attached when something is already attached */ if (ac->ev.data != NULL) - return REDIS_ERR; + return REDICT_ERR; /* Create container for context and r/w events */ - e = (redisIvykisEvents*)hi_malloc(sizeof(*e)); + e = (redictIvykisEvents*)hi_malloc(sizeof(*e)); if (e == NULL) - return REDIS_ERR; + return REDICT_ERR; e->context = ac; /* Register functions to start/stop listening for events */ - ac->ev.addRead = redisIvykisAddRead; - ac->ev.delRead = redisIvykisDelRead; - ac->ev.addWrite = redisIvykisAddWrite; - ac->ev.delWrite = redisIvykisDelWrite; - ac->ev.cleanup = redisIvykisCleanup; + ac->ev.addRead = redictIvykisAddRead; + ac->ev.delRead = redictIvykisDelRead; + ac->ev.addWrite = redictIvykisAddWrite; + ac->ev.delWrite = redictIvykisDelWrite; + ac->ev.cleanup = redictIvykisCleanup; ac->ev.data = e; /* Initialize and install read/write events */ IV_FD_INIT(&e->fd); e->fd.fd = c->fd; - e->fd.handler_in = redisIvykisReadEvent; - e->fd.handler_out = redisIvykisWriteEvent; + e->fd.handler_in = redictIvykisReadEvent; + e->fd.handler_out = redictIvykisWriteEvent; e->fd.handler_err = NULL; e->fd.cookie = e->context; iv_fd_register(&e->fd); - return REDIS_OK; + return REDICT_OK; } #endif diff --git a/adapters/libev.h b/adapters/libev.h index 265e642..9aa841e 100644 --- a/adapters/libev.h +++ b/adapters/libev.h @@ -11,44 +11,44 @@ * */ -#ifndef __HIREDIS_LIBEV_H__ -#define __HIREDIS_LIBEV_H__ +#ifndef __HIREDICT_LIBEV_H__ +#define __HIREDICT_LIBEV_H__ #include #include #include #include "../hiredict.h" #include "../async.h" -typedef struct redisLibevEvents { - redisAsyncContext *context; +typedef struct redictLibevEvents { + redictAsyncContext *context; struct ev_loop *loop; int reading, writing; ev_io rev, wev; ev_timer timer; -} redisLibevEvents; +} redictLibevEvents; -static void redisLibevReadEvent(EV_P_ ev_io *watcher, int revents) { +static void redictLibevReadEvent(EV_P_ ev_io *watcher, int revents) { #if EV_MULTIPLICITY ((void)EV_A); #endif ((void)revents); - redisLibevEvents *e = (redisLibevEvents*)watcher->data; - redisAsyncHandleRead(e->context); + redictLibevEvents *e = (redictLibevEvents*)watcher->data; + redictAsyncHandleRead(e->context); } -static void redisLibevWriteEvent(EV_P_ ev_io *watcher, int revents) { +static void redictLibevWriteEvent(EV_P_ ev_io *watcher, int revents) { #if EV_MULTIPLICITY ((void)EV_A); #endif ((void)revents); - redisLibevEvents *e = (redisLibevEvents*)watcher->data; - redisAsyncHandleWrite(e->context); + redictLibevEvents *e = (redictLibevEvents*)watcher->data; + redictAsyncHandleWrite(e->context); } -static void redisLibevAddRead(void *privdata) { - redisLibevEvents *e = (redisLibevEvents*)privdata; +static void redictLibevAddRead(void *privdata) { + redictLibevEvents *e = (redictLibevEvents*)privdata; #if EV_MULTIPLICITY struct ev_loop *loop = e->loop; #endif @@ -58,8 +58,8 @@ static void redisLibevAddRead(void *privdata) { } } -static void redisLibevDelRead(void *privdata) { - redisLibevEvents *e = (redisLibevEvents*)privdata; +static void redictLibevDelRead(void *privdata) { + redictLibevEvents *e = (redictLibevEvents*)privdata; #if EV_MULTIPLICITY struct ev_loop *loop = e->loop; #endif @@ -69,8 +69,8 @@ static void redisLibevDelRead(void *privdata) { } } -static void redisLibevAddWrite(void *privdata) { - redisLibevEvents *e = (redisLibevEvents*)privdata; +static void redictLibevAddWrite(void *privdata) { + redictLibevEvents *e = (redictLibevEvents*)privdata; #if EV_MULTIPLICITY struct ev_loop *loop = e->loop; #endif @@ -80,8 +80,8 @@ static void redisLibevAddWrite(void *privdata) { } } -static void redisLibevDelWrite(void *privdata) { - redisLibevEvents *e = (redisLibevEvents*)privdata; +static void redictLibevDelWrite(void *privdata) { + redictLibevEvents *e = (redictLibevEvents*)privdata; #if EV_MULTIPLICITY struct ev_loop *loop = e->loop; #endif @@ -91,39 +91,39 @@ static void redisLibevDelWrite(void *privdata) { } } -static void redisLibevStopTimer(void *privdata) { - redisLibevEvents *e = (redisLibevEvents*)privdata; +static void redictLibevStopTimer(void *privdata) { + redictLibevEvents *e = (redictLibevEvents*)privdata; #if EV_MULTIPLICITY struct ev_loop *loop = e->loop; #endif ev_timer_stop(EV_A_ &e->timer); } -static void redisLibevCleanup(void *privdata) { - redisLibevEvents *e = (redisLibevEvents*)privdata; - redisLibevDelRead(privdata); - redisLibevDelWrite(privdata); - redisLibevStopTimer(privdata); +static void redictLibevCleanup(void *privdata) { + redictLibevEvents *e = (redictLibevEvents*)privdata; + redictLibevDelRead(privdata); + redictLibevDelWrite(privdata); + redictLibevStopTimer(privdata); hi_free(e); } -static void redisLibevTimeout(EV_P_ ev_timer *timer, int revents) { +static void redictLibevTimeout(EV_P_ ev_timer *timer, int revents) { #if EV_MULTIPLICITY ((void)EV_A); #endif ((void)revents); - redisLibevEvents *e = (redisLibevEvents*)timer->data; - redisAsyncHandleTimeout(e->context); + redictLibevEvents *e = (redictLibevEvents*)timer->data; + redictAsyncHandleTimeout(e->context); } -static void redisLibevSetTimeout(void *privdata, struct timeval tv) { - redisLibevEvents *e = (redisLibevEvents*)privdata; +static void redictLibevSetTimeout(void *privdata, struct timeval tv) { + redictLibevEvents *e = (redictLibevEvents*)privdata; #if EV_MULTIPLICITY struct ev_loop *loop = e->loop; #endif if (!ev_is_active(&e->timer)) { - ev_init(&e->timer, redisLibevTimeout); + ev_init(&e->timer, redictLibevTimeout); e->timer.data = e; } @@ -131,18 +131,18 @@ static void redisLibevSetTimeout(void *privdata, struct timeval tv) { ev_timer_again(EV_A_ &e->timer); } -static int redisLibevAttach(EV_P_ redisAsyncContext *ac) { - redisContext *c = &(ac->c); - redisLibevEvents *e; +static int redictLibevAttach(EV_P_ redictAsyncContext *ac) { + redictContext *c = &(ac->c); + redictLibevEvents *e; /* Nothing should be attached when something is already attached */ if (ac->ev.data != NULL) - return REDIS_ERR; + return REDICT_ERR; /* Create container for context and r/w events */ - e = (redisLibevEvents*)hi_calloc(1, sizeof(*e)); + e = (redictLibevEvents*)hi_calloc(1, sizeof(*e)); if (e == NULL) - return REDIS_ERR; + return REDICT_ERR; e->context = ac; #if EV_MULTIPLICITY @@ -154,18 +154,18 @@ static int redisLibevAttach(EV_P_ redisAsyncContext *ac) { e->wev.data = e; /* Register functions to start/stop listening for events */ - ac->ev.addRead = redisLibevAddRead; - ac->ev.delRead = redisLibevDelRead; - ac->ev.addWrite = redisLibevAddWrite; - ac->ev.delWrite = redisLibevDelWrite; - ac->ev.cleanup = redisLibevCleanup; - ac->ev.scheduleTimer = redisLibevSetTimeout; + ac->ev.addRead = redictLibevAddRead; + ac->ev.delRead = redictLibevDelRead; + ac->ev.addWrite = redictLibevAddWrite; + ac->ev.delWrite = redictLibevDelWrite; + ac->ev.cleanup = redictLibevCleanup; + ac->ev.scheduleTimer = redictLibevSetTimeout; ac->ev.data = e; /* Initialize read/write events */ - ev_io_init(&e->rev,redisLibevReadEvent,c->fd,EV_READ); - ev_io_init(&e->wev,redisLibevWriteEvent,c->fd,EV_WRITE); - return REDIS_OK; + ev_io_init(&e->rev,redictLibevReadEvent,c->fd,EV_READ); + ev_io_init(&e->wev,redictLibevWriteEvent,c->fd,EV_WRITE); + return REDICT_OK; } #endif diff --git a/adapters/libevent.h b/adapters/libevent.h index 936c37e..66ce6b6 100644 --- a/adapters/libevent.h +++ b/adapters/libevent.h @@ -9,59 +9,59 @@ * */ -#ifndef __HIREDIS_LIBEVENT_H__ -#define __HIREDIS_LIBEVENT_H__ +#ifndef __HIREDICT_LIBEVENT_H__ +#define __HIREDICT_LIBEVENT_H__ #include #include "../hiredict.h" #include "../async.h" -#define REDIS_LIBEVENT_DELETED 0x01 -#define REDIS_LIBEVENT_ENTERED 0x02 +#define REDICT_LIBEVENT_DELETED 0x01 +#define REDICT_LIBEVENT_ENTERED 0x02 -typedef struct redisLibeventEvents { - redisAsyncContext *context; +typedef struct redictLibeventEvents { + redictAsyncContext *context; struct event *ev; struct event_base *base; struct timeval tv; short flags; short state; -} redisLibeventEvents; +} redictLibeventEvents; -static void redisLibeventDestroy(redisLibeventEvents *e) { +static void redictLibeventDestroy(redictLibeventEvents *e) { hi_free(e); } -static void redisLibeventHandler(evutil_socket_t fd, short event, void *arg) { +static void redictLibeventHandler(evutil_socket_t fd, short event, void *arg) { ((void)fd); - redisLibeventEvents *e = (redisLibeventEvents*)arg; - e->state |= REDIS_LIBEVENT_ENTERED; + redictLibeventEvents *e = (redictLibeventEvents*)arg; + e->state |= REDICT_LIBEVENT_ENTERED; - #define CHECK_DELETED() if (e->state & REDIS_LIBEVENT_DELETED) {\ - redisLibeventDestroy(e);\ + #define CHECK_DELETED() if (e->state & REDICT_LIBEVENT_DELETED) {\ + redictLibeventDestroy(e);\ return; \ } - if ((event & EV_TIMEOUT) && (e->state & REDIS_LIBEVENT_DELETED) == 0) { - redisAsyncHandleTimeout(e->context); + if ((event & EV_TIMEOUT) && (e->state & REDICT_LIBEVENT_DELETED) == 0) { + redictAsyncHandleTimeout(e->context); CHECK_DELETED(); } - if ((event & EV_READ) && e->context && (e->state & REDIS_LIBEVENT_DELETED) == 0) { - redisAsyncHandleRead(e->context); + if ((event & EV_READ) && e->context && (e->state & REDICT_LIBEVENT_DELETED) == 0) { + redictAsyncHandleRead(e->context); CHECK_DELETED(); } - if ((event & EV_WRITE) && e->context && (e->state & REDIS_LIBEVENT_DELETED) == 0) { - redisAsyncHandleWrite(e->context); + if ((event & EV_WRITE) && e->context && (e->state & REDICT_LIBEVENT_DELETED) == 0) { + redictAsyncHandleWrite(e->context); CHECK_DELETED(); } - e->state &= ~REDIS_LIBEVENT_ENTERED; + e->state &= ~REDICT_LIBEVENT_ENTERED; #undef CHECK_DELETED } -static void redisLibeventUpdate(void *privdata, short flag, int isRemove) { - redisLibeventEvents *e = (redisLibeventEvents *)privdata; +static void redictLibeventUpdate(void *privdata, short flag, int isRemove) { + redictLibeventEvents *e = (redictLibeventEvents *)privdata; const struct timeval *tv = e->tv.tv_sec || e->tv.tv_usec ? &e->tv : NULL; if (isRemove) { @@ -80,28 +80,28 @@ static void redisLibeventUpdate(void *privdata, short flag, int isRemove) { event_del(e->ev); event_assign(e->ev, e->base, e->context->c.fd, e->flags | EV_PERSIST, - redisLibeventHandler, privdata); + redictLibeventHandler, privdata); event_add(e->ev, tv); } -static void redisLibeventAddRead(void *privdata) { - redisLibeventUpdate(privdata, EV_READ, 0); +static void redictLibeventAddRead(void *privdata) { + redictLibeventUpdate(privdata, EV_READ, 0); } -static void redisLibeventDelRead(void *privdata) { - redisLibeventUpdate(privdata, EV_READ, 1); +static void redictLibeventDelRead(void *privdata) { + redictLibeventUpdate(privdata, EV_READ, 1); } -static void redisLibeventAddWrite(void *privdata) { - redisLibeventUpdate(privdata, EV_WRITE, 0); +static void redictLibeventAddWrite(void *privdata) { + redictLibeventUpdate(privdata, EV_WRITE, 0); } -static void redisLibeventDelWrite(void *privdata) { - redisLibeventUpdate(privdata, EV_WRITE, 1); +static void redictLibeventDelWrite(void *privdata) { + redictLibeventUpdate(privdata, EV_WRITE, 1); } -static void redisLibeventCleanup(void *privdata) { - redisLibeventEvents *e = (redisLibeventEvents*)privdata; +static void redictLibeventCleanup(void *privdata) { + redictLibeventEvents *e = (redictLibeventEvents*)privdata; if (!e) { return; } @@ -109,48 +109,48 @@ static void redisLibeventCleanup(void *privdata) { event_free(e->ev); e->ev = NULL; - if (e->state & REDIS_LIBEVENT_ENTERED) { - e->state |= REDIS_LIBEVENT_DELETED; + if (e->state & REDICT_LIBEVENT_ENTERED) { + e->state |= REDICT_LIBEVENT_DELETED; } else { - redisLibeventDestroy(e); + redictLibeventDestroy(e); } } -static void redisLibeventSetTimeout(void *privdata, struct timeval tv) { - redisLibeventEvents *e = (redisLibeventEvents *)privdata; +static void redictLibeventSetTimeout(void *privdata, struct timeval tv) { + redictLibeventEvents *e = (redictLibeventEvents *)privdata; short flags = e->flags; e->flags = 0; e->tv = tv; - redisLibeventUpdate(e, flags, 0); + redictLibeventUpdate(e, flags, 0); } -static int redisLibeventAttach(redisAsyncContext *ac, struct event_base *base) { - redisContext *c = &(ac->c); - redisLibeventEvents *e; +static int redictLibeventAttach(redictAsyncContext *ac, struct event_base *base) { + redictContext *c = &(ac->c); + redictLibeventEvents *e; /* Nothing should be attached when something is already attached */ if (ac->ev.data != NULL) - return REDIS_ERR; + return REDICT_ERR; /* Create container for context and r/w events */ - e = (redisLibeventEvents*)hi_calloc(1, sizeof(*e)); + e = (redictLibeventEvents*)hi_calloc(1, sizeof(*e)); if (e == NULL) - return REDIS_ERR; + return REDICT_ERR; e->context = ac; /* Register functions to start/stop listening for events */ - ac->ev.addRead = redisLibeventAddRead; - ac->ev.delRead = redisLibeventDelRead; - ac->ev.addWrite = redisLibeventAddWrite; - ac->ev.delWrite = redisLibeventDelWrite; - ac->ev.cleanup = redisLibeventCleanup; - ac->ev.scheduleTimer = redisLibeventSetTimeout; + ac->ev.addRead = redictLibeventAddRead; + ac->ev.delRead = redictLibeventDelRead; + ac->ev.addWrite = redictLibeventAddWrite; + ac->ev.delWrite = redictLibeventDelWrite; + ac->ev.cleanup = redictLibeventCleanup; + ac->ev.scheduleTimer = redictLibeventSetTimeout; ac->ev.data = e; /* Initialize and install read/write events */ - e->ev = event_new(base, c->fd, EV_READ | EV_WRITE, redisLibeventHandler, e); + e->ev = event_new(base, c->fd, EV_READ | EV_WRITE, redictLibeventHandler, e); e->base = base; - return REDIS_OK; + return REDICT_OK; } #endif diff --git a/adapters/libhv.h b/adapters/libhv.h index 4955bb4..2d6fd77 100644 --- a/adapters/libhv.h +++ b/adapters/libhv.h @@ -9,52 +9,52 @@ * */ -#ifndef __HIREDIS_LIBHV_H__ -#define __HIREDIS_LIBHV_H__ +#ifndef __HIREDICT_LIBHV_H__ +#define __HIREDICT_LIBHV_H__ #include #include "../hiredict.h" #include "../async.h" -typedef struct redisLibhvEvents { +typedef struct redictLibhvEvents { hio_t *io; htimer_t *timer; -} redisLibhvEvents; +} redictLibhvEvents; -static void redisLibhvHandleEvents(hio_t* io) { - redisAsyncContext* context = (redisAsyncContext*)hevent_userdata(io); +static void redictLibhvHandleEvents(hio_t* io) { + redictAsyncContext* context = (redictAsyncContext*)hevent_userdata(io); int events = hio_events(io); int revents = hio_revents(io); if (context && (events & HV_READ) && (revents & HV_READ)) { - redisAsyncHandleRead(context); + redictAsyncHandleRead(context); } if (context && (events & HV_WRITE) && (revents & HV_WRITE)) { - redisAsyncHandleWrite(context); + redictAsyncHandleWrite(context); } } -static void redisLibhvAddRead(void *privdata) { - redisLibhvEvents* events = (redisLibhvEvents*)privdata; - hio_add(events->io, redisLibhvHandleEvents, HV_READ); +static void redictLibhvAddRead(void *privdata) { + redictLibhvEvents* events = (redictLibhvEvents*)privdata; + hio_add(events->io, redictLibhvHandleEvents, HV_READ); } -static void redisLibhvDelRead(void *privdata) { - redisLibhvEvents* events = (redisLibhvEvents*)privdata; +static void redictLibhvDelRead(void *privdata) { + redictLibhvEvents* events = (redictLibhvEvents*)privdata; hio_del(events->io, HV_READ); } -static void redisLibhvAddWrite(void *privdata) { - redisLibhvEvents* events = (redisLibhvEvents*)privdata; - hio_add(events->io, redisLibhvHandleEvents, HV_WRITE); +static void redictLibhvAddWrite(void *privdata) { + redictLibhvEvents* events = (redictLibhvEvents*)privdata; + hio_add(events->io, redictLibhvHandleEvents, HV_WRITE); } -static void redisLibhvDelWrite(void *privdata) { - redisLibhvEvents* events = (redisLibhvEvents*)privdata; +static void redictLibhvDelWrite(void *privdata) { + redictLibhvEvents* events = (redictLibhvEvents*)privdata; hio_del(events->io, HV_WRITE); } -static void redisLibhvCleanup(void *privdata) { - redisLibhvEvents* events = (redisLibhvEvents*)privdata; +static void redictLibhvCleanup(void *privdata) { + redictLibhvEvents* events = (redictLibhvEvents*)privdata; if (events->timer) htimer_del(events->timer); @@ -65,17 +65,17 @@ static void redisLibhvCleanup(void *privdata) { hi_free(events); } -static void redisLibhvTimeout(htimer_t* timer) { +static void redictLibhvTimeout(htimer_t* timer) { hio_t* io = (hio_t*)hevent_userdata(timer); - redisAsyncHandleTimeout((redisAsyncContext*)hevent_userdata(io)); + redictAsyncHandleTimeout((redictAsyncContext*)hevent_userdata(io)); } -static void redisLibhvSetTimeout(void *privdata, struct timeval tv) { - redisLibhvEvents* events; +static void redictLibhvSetTimeout(void *privdata, struct timeval tv) { + redictLibhvEvents* events; uint32_t millis; hloop_t* loop; - events = (redisLibhvEvents*)privdata; + events = (redictLibhvEvents*)privdata; millis = tv.tv_sec * 1000 + tv.tv_usec / 1000; if (millis == 0) { @@ -87,7 +87,7 @@ static void redisLibhvSetTimeout(void *privdata, struct timeval tv) { } else if (events->timer == NULL) { /* Add new timer */ loop = hevent_loop(events->io); - events->timer = htimer_add(loop, redisLibhvTimeout, millis, 1); + events->timer = htimer_add(loop, redictLibhvTimeout, millis, 1); hevent_set_userdata(events->timer, events->io); } else { /* Update existing timer */ @@ -95,25 +95,25 @@ static void redisLibhvSetTimeout(void *privdata, struct timeval tv) { } } -static int redisLibhvAttach(redisAsyncContext* ac, hloop_t* loop) { - redisContext *c = &(ac->c); - redisLibhvEvents *events; +static int redictLibhvAttach(redictAsyncContext* ac, hloop_t* loop) { + redictContext *c = &(ac->c); + redictLibhvEvents *events; hio_t* io = NULL; if (ac->ev.data != NULL) { - return REDIS_ERR; + return REDICT_ERR; } /* Create container struct to keep track of our io and any timer */ - events = (redisLibhvEvents*)hi_malloc(sizeof(*events)); + events = (redictLibhvEvents*)hi_malloc(sizeof(*events)); if (events == NULL) { - return REDIS_ERR; + return REDICT_ERR; } io = hio_get(loop, c->fd); if (io == NULL) { hi_free(events); - return REDIS_ERR; + return REDICT_ERR; } hevent_set_userdata(io, ac); @@ -121,14 +121,14 @@ static int redisLibhvAttach(redisAsyncContext* ac, hloop_t* loop) { events->io = io; events->timer = NULL; - ac->ev.addRead = redisLibhvAddRead; - ac->ev.delRead = redisLibhvDelRead; - ac->ev.addWrite = redisLibhvAddWrite; - ac->ev.delWrite = redisLibhvDelWrite; - ac->ev.cleanup = redisLibhvCleanup; - ac->ev.scheduleTimer = redisLibhvSetTimeout; + ac->ev.addRead = redictLibhvAddRead; + ac->ev.delRead = redictLibhvDelRead; + ac->ev.addWrite = redictLibhvAddWrite; + ac->ev.delWrite = redictLibhvDelWrite; + ac->ev.cleanup = redictLibhvCleanup; + ac->ev.scheduleTimer = redictLibhvSetTimeout; ac->ev.data = events; - return REDIS_OK; + return REDICT_OK; } #endif diff --git a/adapters/libsdevent.h b/adapters/libsdevent.h index dc4249a..103d69e 100644 --- a/adapters/libsdevent.h +++ b/adapters/libsdevent.h @@ -9,26 +9,26 @@ * */ -#ifndef HIREDIS_LIBSDEVENT_H -#define HIREDIS_LIBSDEVENT_H +#ifndef HIREDICT_LIBSDEVENT_H +#define HIREDICT_LIBSDEVENT_H #include #include "../hiredict.h" #include "../async.h" -#define REDIS_LIBSDEVENT_DELETED 0x01 -#define REDIS_LIBSDEVENT_ENTERED 0x02 +#define REDICT_LIBSDEVENT_DELETED 0x01 +#define REDICT_LIBSDEVENT_ENTERED 0x02 -typedef struct redisLibsdeventEvents { - redisAsyncContext *context; +typedef struct redictLibsdeventEvents { + redictAsyncContext *context; struct sd_event *event; struct sd_event_source *fdSource; struct sd_event_source *timerSource; int fd; short flags; short state; -} redisLibsdeventEvents; +} redictLibsdeventEvents; -static void redisLibsdeventDestroy(redisLibsdeventEvents *e) { +static void redictLibsdeventDestroy(redictLibsdeventEvents *e) { if (e->fdSource) { e->fdSource = sd_event_source_disable_unref(e->fdSource); } @@ -39,43 +39,43 @@ static void redisLibsdeventDestroy(redisLibsdeventEvents *e) { hi_free(e); } -static int redisLibsdeventTimeoutHandler(sd_event_source *s, uint64_t usec, void *userdata) { +static int redictLibsdeventTimeoutHandler(sd_event_source *s, uint64_t usec, void *userdata) { ((void)s); ((void)usec); - redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata; - redisAsyncHandleTimeout(e->context); + redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata; + redictAsyncHandleTimeout(e->context); return 0; } -static int redisLibsdeventHandler(sd_event_source *s, int fd, uint32_t event, void *userdata) { +static int redictLibsdeventHandler(sd_event_source *s, int fd, uint32_t event, void *userdata) { ((void)s); ((void)fd); - redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata; - e->state |= REDIS_LIBSDEVENT_ENTERED; + redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata; + e->state |= REDICT_LIBSDEVENT_ENTERED; -#define CHECK_DELETED() if (e->state & REDIS_LIBSDEVENT_DELETED) {\ - redisLibsdeventDestroy(e);\ +#define CHECK_DELETED() if (e->state & REDICT_LIBSDEVENT_DELETED) {\ + redictLibsdeventDestroy(e);\ return 0; \ } - if ((event & EPOLLIN) && e->context && (e->state & REDIS_LIBSDEVENT_DELETED) == 0) { - redisAsyncHandleRead(e->context); + if ((event & EPOLLIN) && e->context && (e->state & REDICT_LIBSDEVENT_DELETED) == 0) { + redictAsyncHandleRead(e->context); CHECK_DELETED(); } - if ((event & EPOLLOUT) && e->context && (e->state & REDIS_LIBSDEVENT_DELETED) == 0) { - redisAsyncHandleWrite(e->context); + if ((event & EPOLLOUT) && e->context && (e->state & REDICT_LIBSDEVENT_DELETED) == 0) { + redictAsyncHandleWrite(e->context); CHECK_DELETED(); } - e->state &= ~REDIS_LIBSDEVENT_ENTERED; + e->state &= ~REDICT_LIBSDEVENT_ENTERED; #undef CHECK_DELETED return 0; } -static void redisLibsdeventAddRead(void *userdata) { - redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata; +static void redictLibsdeventAddRead(void *userdata) { + redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata; if (e->flags & EPOLLIN) { return; @@ -86,12 +86,12 @@ static void redisLibsdeventAddRead(void *userdata) { if (e->flags & EPOLLOUT) { sd_event_source_set_io_events(e->fdSource, e->flags); } else { - sd_event_add_io(e->event, &e->fdSource, e->fd, e->flags, redisLibsdeventHandler, e); + sd_event_add_io(e->event, &e->fdSource, e->fd, e->flags, redictLibsdeventHandler, e); } } -static void redisLibsdeventDelRead(void *userdata) { - redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata; +static void redictLibsdeventDelRead(void *userdata) { + redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata; e->flags &= ~EPOLLIN; @@ -102,8 +102,8 @@ static void redisLibsdeventDelRead(void *userdata) { } } -static void redisLibsdeventAddWrite(void *userdata) { - redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata; +static void redictLibsdeventAddWrite(void *userdata) { + redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata; if (e->flags & EPOLLOUT) { return; @@ -114,12 +114,12 @@ static void redisLibsdeventAddWrite(void *userdata) { if (e->flags & EPOLLIN) { sd_event_source_set_io_events(e->fdSource, e->flags); } else { - sd_event_add_io(e->event, &e->fdSource, e->fd, e->flags, redisLibsdeventHandler, e); + sd_event_add_io(e->event, &e->fdSource, e->fd, e->flags, redictLibsdeventHandler, e); } } -static void redisLibsdeventDelWrite(void *userdata) { - redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata; +static void redictLibsdeventDelWrite(void *userdata) { + redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata; e->flags &= ~EPOLLOUT; @@ -130,43 +130,43 @@ static void redisLibsdeventDelWrite(void *userdata) { } } -static void redisLibsdeventCleanup(void *userdata) { - redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata; +static void redictLibsdeventCleanup(void *userdata) { + redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata; if (!e) { return; } - if (e->state & REDIS_LIBSDEVENT_ENTERED) { - e->state |= REDIS_LIBSDEVENT_DELETED; + if (e->state & REDICT_LIBSDEVENT_ENTERED) { + e->state |= REDICT_LIBSDEVENT_DELETED; } else { - redisLibsdeventDestroy(e); + redictLibsdeventDestroy(e); } } -static void redisLibsdeventSetTimeout(void *userdata, struct timeval tv) { - redisLibsdeventEvents *e = (redisLibsdeventEvents *)userdata; +static void redictLibsdeventSetTimeout(void *userdata, struct timeval tv) { + redictLibsdeventEvents *e = (redictLibsdeventEvents *)userdata; uint64_t usec = tv.tv_sec * 1000000 + tv.tv_usec; if (!e->timerSource) { - sd_event_add_time_relative(e->event, &e->timerSource, CLOCK_MONOTONIC, usec, 1, redisLibsdeventTimeoutHandler, e); + sd_event_add_time_relative(e->event, &e->timerSource, CLOCK_MONOTONIC, usec, 1, redictLibsdeventTimeoutHandler, e); } else { sd_event_source_set_time_relative(e->timerSource, usec); } } -static int redisLibsdeventAttach(redisAsyncContext *ac, struct sd_event *event) { - redisContext *c = &(ac->c); - redisLibsdeventEvents *e; +static int redictLibsdeventAttach(redictAsyncContext *ac, struct sd_event *event) { + redictContext *c = &(ac->c); + redictLibsdeventEvents *e; /* Nothing should be attached when something is already attached */ if (ac->ev.data != NULL) - return REDIS_ERR; + return REDICT_ERR; /* Create container for context and r/w events */ - e = (redisLibsdeventEvents*)hi_calloc(1, sizeof(*e)); + e = (redictLibsdeventEvents*)hi_calloc(1, sizeof(*e)); if (e == NULL) - return REDIS_ERR; + return REDICT_ERR; /* Initialize and increase event refcount */ e->context = ac; @@ -175,14 +175,14 @@ static int redisLibsdeventAttach(redisAsyncContext *ac, struct sd_event *event) sd_event_ref(event); /* Register functions to start/stop listening for events */ - ac->ev.addRead = redisLibsdeventAddRead; - ac->ev.delRead = redisLibsdeventDelRead; - ac->ev.addWrite = redisLibsdeventAddWrite; - ac->ev.delWrite = redisLibsdeventDelWrite; - ac->ev.cleanup = redisLibsdeventCleanup; - ac->ev.scheduleTimer = redisLibsdeventSetTimeout; + ac->ev.addRead = redictLibsdeventAddRead; + ac->ev.delRead = redictLibsdeventDelRead; + ac->ev.addWrite = redictLibsdeventAddWrite; + ac->ev.delWrite = redictLibsdeventDelWrite; + ac->ev.cleanup = redictLibsdeventCleanup; + ac->ev.scheduleTimer = redictLibsdeventSetTimeout; ac->ev.data = e; - return REDIS_OK; + return REDICT_OK; } #endif diff --git a/adapters/libuv.h b/adapters/libuv.h index 317d5e1..e91b872 100644 --- a/adapters/libuv.h +++ b/adapters/libuv.h @@ -9,37 +9,37 @@ * */ -#ifndef __HIREDIS_LIBUV_H__ -#define __HIREDIS_LIBUV_H__ +#ifndef __HIREDICT_LIBUV_H__ +#define __HIREDICT_LIBUV_H__ #include #include #include "../hiredict.h" #include "../async.h" #include -typedef struct redisLibuvEvents { - redisAsyncContext* context; +typedef struct redictLibuvEvents { + redictAsyncContext* context; uv_poll_t handle; uv_timer_t timer; int events; -} redisLibuvEvents; +} redictLibuvEvents; -static void redisLibuvPoll(uv_poll_t* handle, int status, int events) { - redisLibuvEvents* p = (redisLibuvEvents*)handle->data; +static void redictLibuvPoll(uv_poll_t* handle, int status, int events) { + redictLibuvEvents* p = (redictLibuvEvents*)handle->data; int ev = (status ? p->events : events); if (p->context != NULL && (ev & UV_READABLE)) { - redisAsyncHandleRead(p->context); + redictAsyncHandleRead(p->context); } if (p->context != NULL && (ev & UV_WRITABLE)) { - redisAsyncHandleWrite(p->context); + redictAsyncHandleWrite(p->context); } } -static void redisLibuvAddRead(void *privdata) { - redisLibuvEvents* p = (redisLibuvEvents*)privdata; +static void redictLibuvAddRead(void *privdata) { + redictLibuvEvents* p = (redictLibuvEvents*)privdata; if (p->events & UV_READABLE) { return; @@ -47,25 +47,25 @@ static void redisLibuvAddRead(void *privdata) { p->events |= UV_READABLE; - uv_poll_start(&p->handle, p->events, redisLibuvPoll); + uv_poll_start(&p->handle, p->events, redictLibuvPoll); } -static void redisLibuvDelRead(void *privdata) { - redisLibuvEvents* p = (redisLibuvEvents*)privdata; +static void redictLibuvDelRead(void *privdata) { + redictLibuvEvents* p = (redictLibuvEvents*)privdata; p->events &= ~UV_READABLE; if (p->events) { - uv_poll_start(&p->handle, p->events, redisLibuvPoll); + uv_poll_start(&p->handle, p->events, redictLibuvPoll); } else { uv_poll_stop(&p->handle); } } -static void redisLibuvAddWrite(void *privdata) { - redisLibuvEvents* p = (redisLibuvEvents*)privdata; +static void redictLibuvAddWrite(void *privdata) { + redictLibuvEvents* p = (redictLibuvEvents*)privdata; if (p->events & UV_WRITABLE) { return; @@ -73,24 +73,24 @@ static void redisLibuvAddWrite(void *privdata) { p->events |= UV_WRITABLE; - uv_poll_start(&p->handle, p->events, redisLibuvPoll); + uv_poll_start(&p->handle, p->events, redictLibuvPoll); } -static void redisLibuvDelWrite(void *privdata) { - redisLibuvEvents* p = (redisLibuvEvents*)privdata; +static void redictLibuvDelWrite(void *privdata) { + redictLibuvEvents* p = (redictLibuvEvents*)privdata; p->events &= ~UV_WRITABLE; if (p->events) { - uv_poll_start(&p->handle, p->events, redisLibuvPoll); + uv_poll_start(&p->handle, p->events, redictLibuvPoll); } else { uv_poll_stop(&p->handle); } } static void on_timer_close(uv_handle_t *handle) { - redisLibuvEvents* p = (redisLibuvEvents*)handle->data; + redictLibuvEvents* p = (redictLibuvEvents*)handle->data; p->timer.data = NULL; if (!p->handle.data) { // both timer and handle are closed @@ -100,7 +100,7 @@ static void on_timer_close(uv_handle_t *handle) { } static void on_handle_close(uv_handle_t *handle) { - redisLibuvEvents* p = (redisLibuvEvents*)handle->data; + redictLibuvEvents* p = (redictLibuvEvents*)handle->data; p->handle.data = NULL; if (!p->timer.data) { // timer never started, or timer already destroyed @@ -113,17 +113,17 @@ static void on_handle_close(uv_handle_t *handle) { // see: https://github.com/libuv/libuv/blob/v0.11.23/include/uv.h #if (UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR < 11) || \ (UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR == 11 && UV_VERSION_PATCH < 23) -static void redisLibuvTimeout(uv_timer_t *timer, int status) { +static void redictLibuvTimeout(uv_timer_t *timer, int status) { (void)status; // unused #else -static void redisLibuvTimeout(uv_timer_t *timer) { +static void redictLibuvTimeout(uv_timer_t *timer) { #endif - redisLibuvEvents *e = (redisLibuvEvents*)timer->data; - redisAsyncHandleTimeout(e->context); + redictLibuvEvents *e = (redictLibuvEvents*)timer->data; + redictAsyncHandleTimeout(e->context); } -static void redisLibuvSetTimeout(void *privdata, struct timeval tv) { - redisLibuvEvents* p = (redisLibuvEvents*)privdata; +static void redictLibuvSetTimeout(void *privdata, struct timeval tv) { + redictLibuvEvents* p = (redictLibuvEvents*)privdata; uint64_t millsec = tv.tv_sec * 1000 + tv.tv_usec / 1000.0; if (!p->timer.data) { @@ -135,11 +135,11 @@ static void redisLibuvSetTimeout(void *privdata, struct timeval tv) { } // updates the timeout if the timer has already started // or start the timer - uv_timer_start(&p->timer, redisLibuvTimeout, millsec, 0); + uv_timer_start(&p->timer, redictLibuvTimeout, millsec, 0); } -static void redisLibuvCleanup(void *privdata) { - redisLibuvEvents* p = (redisLibuvEvents*)privdata; +static void redictLibuvCleanup(void *privdata) { + redictLibuvEvents* p = (redictLibuvEvents*)privdata; p->context = NULL; // indicate that context might no longer exist if (p->timer.data) { @@ -149,35 +149,35 @@ static void redisLibuvCleanup(void *privdata) { } -static int redisLibuvAttach(redisAsyncContext* ac, uv_loop_t* loop) { - redisContext *c = &(ac->c); +static int redictLibuvAttach(redictAsyncContext* ac, uv_loop_t* loop) { + redictContext *c = &(ac->c); if (ac->ev.data != NULL) { - return REDIS_ERR; + return REDICT_ERR; } - ac->ev.addRead = redisLibuvAddRead; - ac->ev.delRead = redisLibuvDelRead; - ac->ev.addWrite = redisLibuvAddWrite; - ac->ev.delWrite = redisLibuvDelWrite; - ac->ev.cleanup = redisLibuvCleanup; - ac->ev.scheduleTimer = redisLibuvSetTimeout; + ac->ev.addRead = redictLibuvAddRead; + ac->ev.delRead = redictLibuvDelRead; + ac->ev.addWrite = redictLibuvAddWrite; + ac->ev.delWrite = redictLibuvDelWrite; + ac->ev.cleanup = redictLibuvCleanup; + ac->ev.scheduleTimer = redictLibuvSetTimeout; - redisLibuvEvents* p = (redisLibuvEvents*)hi_malloc(sizeof(*p)); + redictLibuvEvents* p = (redictLibuvEvents*)hi_malloc(sizeof(*p)); if (p == NULL) - return REDIS_ERR; + return REDICT_ERR; memset(p, 0, sizeof(*p)); if (uv_poll_init_socket(loop, &p->handle, c->fd) != 0) { hi_free(p); - return REDIS_ERR; + return REDICT_ERR; } ac->ev.data = p; p->handle.data = p; p->context = ac; - return REDIS_OK; + return REDICT_OK; } #endif diff --git a/adapters/macosx.h b/adapters/macosx.h index 7ae5e5a..670ca62 100644 --- a/adapters/macosx.h +++ b/adapters/macosx.h @@ -9,8 +9,8 @@ * */ -#ifndef __HIREDIS_MACOSX_H__ -#define __HIREDIS_MACOSX_H__ +#ifndef __HIREDICT_MACOSX_H__ +#define __HIREDICT_MACOSX_H__ #include @@ -18,61 +18,61 @@ #include "../async.h" typedef struct { - redisAsyncContext *context; + redictAsyncContext *context; CFSocketRef socketRef; CFRunLoopSourceRef sourceRef; -} RedisRunLoop; +} RedictRunLoop; -static int freeRedisRunLoop(RedisRunLoop* redisRunLoop) { - if( redisRunLoop != NULL ) { - if( redisRunLoop->sourceRef != NULL ) { - CFRunLoopSourceInvalidate(redisRunLoop->sourceRef); - CFRelease(redisRunLoop->sourceRef); +static int freeRedictRunLoop(RedictRunLoop* redictRunLoop) { + if( redictRunLoop != NULL ) { + if( redictRunLoop->sourceRef != NULL ) { + CFRunLoopSourceInvalidate(redictRunLoop->sourceRef); + CFRelease(redictRunLoop->sourceRef); } - if( redisRunLoop->socketRef != NULL ) { - CFSocketInvalidate(redisRunLoop->socketRef); - CFRelease(redisRunLoop->socketRef); + if( redictRunLoop->socketRef != NULL ) { + CFSocketInvalidate(redictRunLoop->socketRef); + CFRelease(redictRunLoop->socketRef); } - hi_free(redisRunLoop); + hi_free(redictRunLoop); } - return REDIS_ERR; + return REDICT_ERR; } -static void redisMacOSAddRead(void *privdata) { - RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata; - CFSocketEnableCallBacks(redisRunLoop->socketRef, kCFSocketReadCallBack); +static void redictMacOSAddRead(void *privdata) { + RedictRunLoop *redictRunLoop = (RedictRunLoop*)privdata; + CFSocketEnableCallBacks(redictRunLoop->socketRef, kCFSocketReadCallBack); } -static void redisMacOSDelRead(void *privdata) { - RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata; - CFSocketDisableCallBacks(redisRunLoop->socketRef, kCFSocketReadCallBack); +static void redictMacOSDelRead(void *privdata) { + RedictRunLoop *redictRunLoop = (RedictRunLoop*)privdata; + CFSocketDisableCallBacks(redictRunLoop->socketRef, kCFSocketReadCallBack); } -static void redisMacOSAddWrite(void *privdata) { - RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata; - CFSocketEnableCallBacks(redisRunLoop->socketRef, kCFSocketWriteCallBack); +static void redictMacOSAddWrite(void *privdata) { + RedictRunLoop *redictRunLoop = (RedictRunLoop*)privdata; + CFSocketEnableCallBacks(redictRunLoop->socketRef, kCFSocketWriteCallBack); } -static void redisMacOSDelWrite(void *privdata) { - RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata; - CFSocketDisableCallBacks(redisRunLoop->socketRef, kCFSocketWriteCallBack); +static void redictMacOSDelWrite(void *privdata) { + RedictRunLoop *redictRunLoop = (RedictRunLoop*)privdata; + CFSocketDisableCallBacks(redictRunLoop->socketRef, kCFSocketWriteCallBack); } -static void redisMacOSCleanup(void *privdata) { - RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata; - freeRedisRunLoop(redisRunLoop); +static void redictMacOSCleanup(void *privdata) { + RedictRunLoop *redictRunLoop = (RedictRunLoop*)privdata; + freeRedictRunLoop(redictRunLoop); } -static void redisMacOSAsyncCallback(CFSocketRef __unused s, CFSocketCallBackType callbackType, CFDataRef __unused address, const void __unused *data, void *info) { - redisAsyncContext* context = (redisAsyncContext*) info; +static void redictMacOSAsyncCallback(CFSocketRef __unused s, CFSocketCallBackType callbackType, CFDataRef __unused address, const void __unused *data, void *info) { + redictAsyncContext* context = (redictAsyncContext*) info; switch (callbackType) { case kCFSocketReadCallBack: - redisAsyncHandleRead(context); + redictAsyncHandleRead(context); break; case kCFSocketWriteCallBack: - redisAsyncHandleWrite(context); + redictAsyncHandleWrite(context); break; default: @@ -80,41 +80,41 @@ static void redisMacOSAsyncCallback(CFSocketRef __unused s, CFSocketCallBackType } } -static int redisMacOSAttach(redisAsyncContext *redisAsyncCtx, CFRunLoopRef runLoop) { - redisContext *redisCtx = &(redisAsyncCtx->c); +static int redictMacOSAttach(redictAsyncContext *redictAsyncCtx, CFRunLoopRef runLoop) { + redictContext *redictCtx = &(redictAsyncCtx->c); /* Nothing should be attached when something is already attached */ - if( redisAsyncCtx->ev.data != NULL ) return REDIS_ERR; + if( redictAsyncCtx->ev.data != NULL ) return REDICT_ERR; - RedisRunLoop* redisRunLoop = (RedisRunLoop*) hi_calloc(1, sizeof(RedisRunLoop)); - if (redisRunLoop == NULL) - return REDIS_ERR; + RedictRunLoop* redictRunLoop = (RedictRunLoop*) hi_calloc(1, sizeof(RedictRunLoop)); + if (redictRunLoop == NULL) + return REDICT_ERR; - /* Setup redis stuff */ - redisRunLoop->context = redisAsyncCtx; + /* Setup redict stuff */ + redictRunLoop->context = redictAsyncCtx; - redisAsyncCtx->ev.addRead = redisMacOSAddRead; - redisAsyncCtx->ev.delRead = redisMacOSDelRead; - redisAsyncCtx->ev.addWrite = redisMacOSAddWrite; - redisAsyncCtx->ev.delWrite = redisMacOSDelWrite; - redisAsyncCtx->ev.cleanup = redisMacOSCleanup; - redisAsyncCtx->ev.data = redisRunLoop; + redictAsyncCtx->ev.addRead = redictMacOSAddRead; + redictAsyncCtx->ev.delRead = redictMacOSDelRead; + redictAsyncCtx->ev.addWrite = redictMacOSAddWrite; + redictAsyncCtx->ev.delWrite = redictMacOSDelWrite; + redictAsyncCtx->ev.cleanup = redictMacOSCleanup; + redictAsyncCtx->ev.data = redictRunLoop; /* Initialize and install read/write events */ - CFSocketContext socketCtx = { 0, redisAsyncCtx, NULL, NULL, NULL }; + CFSocketContext socketCtx = { 0, redictAsyncCtx, NULL, NULL, NULL }; - redisRunLoop->socketRef = CFSocketCreateWithNative(NULL, redisCtx->fd, + redictRunLoop->socketRef = CFSocketCreateWithNative(NULL, redictCtx->fd, kCFSocketReadCallBack | kCFSocketWriteCallBack, - redisMacOSAsyncCallback, + redictMacOSAsyncCallback, &socketCtx); - if( !redisRunLoop->socketRef ) return freeRedisRunLoop(redisRunLoop); + if( !redictRunLoop->socketRef ) return freeRedictRunLoop(redictRunLoop); - redisRunLoop->sourceRef = CFSocketCreateRunLoopSource(NULL, redisRunLoop->socketRef, 0); - if( !redisRunLoop->sourceRef ) return freeRedisRunLoop(redisRunLoop); + redictRunLoop->sourceRef = CFSocketCreateRunLoopSource(NULL, redictRunLoop->socketRef, 0); + if( !redictRunLoop->sourceRef ) return freeRedictRunLoop(redictRunLoop); - CFRunLoopAddSource(runLoop, redisRunLoop->sourceRef, kCFRunLoopDefaultMode); + CFRunLoopAddSource(runLoop, redictRunLoop->sourceRef, kCFRunLoopDefaultMode); - return REDIS_OK; + return REDICT_OK; } #endif diff --git a/adapters/poll.h b/adapters/poll.h index 23b3eba..adc0aab 100644 --- a/adapters/poll.h +++ b/adapters/poll.h @@ -9,43 +9,43 @@ * */ -#ifndef HIREDIS_POLL_H -#define HIREDIS_POLL_H +#ifndef HIREDICT_POLL_H +#define HIREDICT_POLL_H #include "../async.h" #include "../sockcompat.h" #include // for memset #include -/* Values to return from redisPollTick */ -#define REDIS_POLL_HANDLED_READ 1 -#define REDIS_POLL_HANDLED_WRITE 2 -#define REDIS_POLL_HANDLED_TIMEOUT 4 +/* Values to return from redictPollTick */ +#define REDICT_POLL_HANDLED_READ 1 +#define REDICT_POLL_HANDLED_WRITE 2 +#define REDICT_POLL_HANDLED_TIMEOUT 4 /* An adapter to allow manual polling of the async context by checking the state * of the underlying file descriptor. Useful in cases where there is no formal * IO event loop but regular ticking can be used, such as in game engines. */ -typedef struct redisPollEvents { - redisAsyncContext *context; - redisFD fd; +typedef struct redictPollEvents { + redictAsyncContext *context; + redictFD fd; char reading, writing; char in_tick; char deleted; double deadline; -} redisPollEvents; +} redictPollEvents; -static double redisPollTimevalToDouble(struct timeval *tv) { +static double redictPollTimevalToDouble(struct timeval *tv) { if (tv == NULL) return 0.0; return tv->tv_sec + tv->tv_usec / 1000000.00; } -static double redisPollGetNow(void) { +static double redictPollGetNow(void) { #ifndef _MSC_VER struct timeval tv; gettimeofday(&tv,NULL); - return redisPollTimevalToDouble(&tv); + return redictPollTimevalToDouble(&tv); #else FILETIME ft; ULARGE_INTEGER li; @@ -59,14 +59,14 @@ static double redisPollGetNow(void) { /* Poll for io, handling any pending callbacks. The timeout argument can be * positive to wait for a maximum given time for IO, zero to poll, or negative * to wait forever */ -static int redisPollTick(redisAsyncContext *ac, double timeout) { +static int redictPollTick(redictAsyncContext *ac, double timeout) { int reading, writing; struct pollfd pfd; int handled; int ns; int itimeout; - redisPollEvents *e = (redisPollEvents*)ac->ev.data; + redictPollEvents *e = (redictPollEvents*)ac->ev.data; if (!e) return 0; @@ -101,29 +101,29 @@ static int redisPollTick(redisAsyncContext *ac, double timeout) { e->in_tick = 1; if (ns) { if (reading && (pfd.revents & POLLIN)) { - redisAsyncHandleRead(ac); - handled |= REDIS_POLL_HANDLED_READ; + redictAsyncHandleRead(ac); + handled |= REDICT_POLL_HANDLED_READ; } /* on Windows, connection failure is indicated with the Exception fdset. * handle it the same as writable. */ if (writing && (pfd.revents & (POLLOUT | POLLERR))) { /* context Read callback may have caused context to be deleted, e.g. - by doing an redisAsyncDisconnect() */ + by doing an redictAsyncDisconnect() */ if (!e->deleted) { - redisAsyncHandleWrite(ac); - handled |= REDIS_POLL_HANDLED_WRITE; + redictAsyncHandleWrite(ac); + handled |= REDICT_POLL_HANDLED_WRITE; } } } /* perform timeouts */ if (!e->deleted && e->deadline != 0.0) { - double now = redisPollGetNow(); + double now = redictPollGetNow(); if (now >= e->deadline) { /* deadline has passed. disable timeout and perform callback */ e->deadline = 0.0; - redisAsyncHandleTimeout(ac); - handled |= REDIS_POLL_HANDLED_TIMEOUT; + redictAsyncHandleTimeout(ac); + handled |= REDICT_POLL_HANDLED_TIMEOUT; } } @@ -136,28 +136,28 @@ static int redisPollTick(redisAsyncContext *ac, double timeout) { return handled; } -static void redisPollAddRead(void *data) { - redisPollEvents *e = (redisPollEvents*)data; +static void redictPollAddRead(void *data) { + redictPollEvents *e = (redictPollEvents*)data; e->reading = 1; } -static void redisPollDelRead(void *data) { - redisPollEvents *e = (redisPollEvents*)data; +static void redictPollDelRead(void *data) { + redictPollEvents *e = (redictPollEvents*)data; e->reading = 0; } -static void redisPollAddWrite(void *data) { - redisPollEvents *e = (redisPollEvents*)data; +static void redictPollAddWrite(void *data) { + redictPollEvents *e = (redictPollEvents*)data; e->writing = 1; } -static void redisPollDelWrite(void *data) { - redisPollEvents *e = (redisPollEvents*)data; +static void redictPollDelWrite(void *data) { + redictPollEvents *e = (redictPollEvents*)data; e->writing = 0; } -static void redisPollCleanup(void *data) { - redisPollEvents *e = (redisPollEvents*)data; +static void redictPollCleanup(void *data) { + redictPollEvents *e = (redictPollEvents*)data; /* if we are currently processing a tick, postpone deletion */ if (e->in_tick) @@ -166,25 +166,25 @@ static void redisPollCleanup(void *data) { hi_free(e); } -static void redisPollScheduleTimer(void *data, struct timeval tv) +static void redictPollScheduleTimer(void *data, struct timeval tv) { - redisPollEvents *e = (redisPollEvents*)data; - double now = redisPollGetNow(); - e->deadline = now + redisPollTimevalToDouble(&tv); + redictPollEvents *e = (redictPollEvents*)data; + double now = redictPollGetNow(); + e->deadline = now + redictPollTimevalToDouble(&tv); } -static int redisPollAttach(redisAsyncContext *ac) { - redisContext *c = &(ac->c); - redisPollEvents *e; +static int redictPollAttach(redictAsyncContext *ac) { + redictContext *c = &(ac->c); + redictPollEvents *e; /* Nothing should be attached when something is already attached */ if (ac->ev.data != NULL) - return REDIS_ERR; + return REDICT_ERR; /* Create container for context and r/w events */ - e = (redisPollEvents*)hi_malloc(sizeof(*e)); + e = (redictPollEvents*)hi_malloc(sizeof(*e)); if (e == NULL) - return REDIS_ERR; + return REDICT_ERR; memset(e, 0, sizeof(*e)); e->context = ac; @@ -194,14 +194,14 @@ static int redisPollAttach(redisAsyncContext *ac) { e->deadline = 0.0; /* Register functions to start/stop listening for events */ - ac->ev.addRead = redisPollAddRead; - ac->ev.delRead = redisPollDelRead; - ac->ev.addWrite = redisPollAddWrite; - ac->ev.delWrite = redisPollDelWrite; - ac->ev.scheduleTimer = redisPollScheduleTimer; - ac->ev.cleanup = redisPollCleanup; + ac->ev.addRead = redictPollAddRead; + ac->ev.delRead = redictPollDelRead; + ac->ev.addWrite = redictPollAddWrite; + ac->ev.delWrite = redictPollDelWrite; + ac->ev.scheduleTimer = redictPollScheduleTimer; + ac->ev.cleanup = redictPollCleanup; ac->ev.data = e; - return REDIS_OK; + return REDICT_OK; } -#endif /* HIREDIS_POLL_H */ +#endif /* HIREDICT_POLL_H */ diff --git a/adapters/qt.h b/adapters/qt.h index a75cf31..de8d191 100644 --- a/adapters/qt.h +++ b/adapters/qt.h @@ -9,73 +9,73 @@ * */ -#ifndef __HIREDIS_QT_H__ -#define __HIREDIS_QT_H__ +#ifndef __HIREDICT_QT_H__ +#define __HIREDICT_QT_H__ #include #include "../async.h" -static void RedisQtAddRead(void *); -static void RedisQtDelRead(void *); -static void RedisQtAddWrite(void *); -static void RedisQtDelWrite(void *); -static void RedisQtCleanup(void *); +static void RedictQtAddRead(void *); +static void RedictQtDelRead(void *); +static void RedictQtAddWrite(void *); +static void RedictQtDelWrite(void *); +static void RedictQtCleanup(void *); -class RedisQtAdapter : public QObject { +class RedictQtAdapter : public QObject { Q_OBJECT friend - void RedisQtAddRead(void * adapter) { - RedisQtAdapter * a = static_cast(adapter); + void RedictQtAddRead(void * adapter) { + RedictQtAdapter * a = static_cast(adapter); a->addRead(); } friend - void RedisQtDelRead(void * adapter) { - RedisQtAdapter * a = static_cast(adapter); + void RedictQtDelRead(void * adapter) { + RedictQtAdapter * a = static_cast(adapter); a->delRead(); } friend - void RedisQtAddWrite(void * adapter) { - RedisQtAdapter * a = static_cast(adapter); + void RedictQtAddWrite(void * adapter) { + RedictQtAdapter * a = static_cast(adapter); a->addWrite(); } friend - void RedisQtDelWrite(void * adapter) { - RedisQtAdapter * a = static_cast(adapter); + void RedictQtDelWrite(void * adapter) { + RedictQtAdapter * a = static_cast(adapter); a->delWrite(); } friend - void RedisQtCleanup(void * adapter) { - RedisQtAdapter * a = static_cast(adapter); + void RedictQtCleanup(void * adapter) { + RedictQtAdapter * a = static_cast(adapter); a->cleanup(); } public: - RedisQtAdapter(QObject * parent = 0) + RedictQtAdapter(QObject * parent = 0) : QObject(parent), m_ctx(0), m_read(0), m_write(0) { } - ~RedisQtAdapter() { + ~RedictQtAdapter() { if (m_ctx != 0) { m_ctx->ev.data = NULL; } } - int setContext(redisAsyncContext * ac) { + int setContext(redictAsyncContext * ac) { if (ac->ev.data != NULL) { - return REDIS_ERR; + return REDICT_ERR; } m_ctx = ac; m_ctx->ev.data = this; - m_ctx->ev.addRead = RedisQtAddRead; - m_ctx->ev.delRead = RedisQtDelRead; - m_ctx->ev.addWrite = RedisQtAddWrite; - m_ctx->ev.delWrite = RedisQtDelWrite; - m_ctx->ev.cleanup = RedisQtCleanup; - return REDIS_OK; + m_ctx->ev.addRead = RedictQtAddRead; + m_ctx->ev.delRead = RedictQtDelRead; + m_ctx->ev.addWrite = RedictQtAddWrite; + m_ctx->ev.delWrite = RedictQtDelWrite; + m_ctx->ev.cleanup = RedictQtCleanup; + return REDICT_OK; } private: @@ -109,13 +109,13 @@ class RedisQtAdapter : public QObject { } private slots: - void read() { redisAsyncHandleRead(m_ctx); } - void write() { redisAsyncHandleWrite(m_ctx); } + void read() { redictAsyncHandleRead(m_ctx); } + void write() { redictAsyncHandleWrite(m_ctx); } private: - redisAsyncContext * m_ctx; + redictAsyncContext * m_ctx; QSocketNotifier * m_read; QSocketNotifier * m_write; }; -#endif /* !__HIREDIS_QT_H__ */ +#endif /* !__HIREDICT_QT_H__ */ diff --git a/adapters/redictmoduleapi.h b/adapters/redictmoduleapi.h index 1a134f5..0238ba1 100644 --- a/adapters/redictmoduleapi.h +++ b/adapters/redictmoduleapi.h @@ -9,8 +9,8 @@ * */ -#ifndef __HIREDIS_REDISMODULEAPI_H__ -#define __HIREDIS_REDISMODULEAPI_H__ +#ifndef __HIREDICT_REDICTMODULEAPI_H__ +#define __HIREDICT_REDICTMODULEAPI_H__ #include "redictmodule.h" @@ -19,120 +19,120 @@ #include -typedef struct redisModuleEvents { - redisAsyncContext *context; - RedisModuleCtx *module_ctx; +typedef struct redictModuleEvents { + redictAsyncContext *context; + RedictModuleCtx *module_ctx; int fd; int reading, writing; int timer_active; - RedisModuleTimerID timer_id; -} redisModuleEvents; + RedictModuleTimerID timer_id; +} redictModuleEvents; -static inline void redisModuleReadEvent(int fd, void *privdata, int mask) { +static inline void redictModuleReadEvent(int fd, void *privdata, int mask) { (void) fd; (void) mask; - redisModuleEvents *e = (redisModuleEvents*)privdata; - redisAsyncHandleRead(e->context); + redictModuleEvents *e = (redictModuleEvents*)privdata; + redictAsyncHandleRead(e->context); } -static inline void redisModuleWriteEvent(int fd, void *privdata, int mask) { +static inline void redictModuleWriteEvent(int fd, void *privdata, int mask) { (void) fd; (void) mask; - redisModuleEvents *e = (redisModuleEvents*)privdata; - redisAsyncHandleWrite(e->context); + redictModuleEvents *e = (redictModuleEvents*)privdata; + redictAsyncHandleWrite(e->context); } -static inline void redisModuleAddRead(void *privdata) { - redisModuleEvents *e = (redisModuleEvents*)privdata; +static inline void redictModuleAddRead(void *privdata) { + redictModuleEvents *e = (redictModuleEvents*)privdata; if (!e->reading) { e->reading = 1; - RedisModule_EventLoopAdd(e->fd, REDISMODULE_EVENTLOOP_READABLE, redisModuleReadEvent, e); + RedictModule_EventLoopAdd(e->fd, REDICTMODULE_EVENTLOOP_READABLE, redictModuleReadEvent, e); } } -static inline void redisModuleDelRead(void *privdata) { - redisModuleEvents *e = (redisModuleEvents*)privdata; +static inline void redictModuleDelRead(void *privdata) { + redictModuleEvents *e = (redictModuleEvents*)privdata; if (e->reading) { e->reading = 0; - RedisModule_EventLoopDel(e->fd, REDISMODULE_EVENTLOOP_READABLE); + RedictModule_EventLoopDel(e->fd, REDICTMODULE_EVENTLOOP_READABLE); } } -static inline void redisModuleAddWrite(void *privdata) { - redisModuleEvents *e = (redisModuleEvents*)privdata; +static inline void redictModuleAddWrite(void *privdata) { + redictModuleEvents *e = (redictModuleEvents*)privdata; if (!e->writing) { e->writing = 1; - RedisModule_EventLoopAdd(e->fd, REDISMODULE_EVENTLOOP_WRITABLE, redisModuleWriteEvent, e); + RedictModule_EventLoopAdd(e->fd, REDICTMODULE_EVENTLOOP_WRITABLE, redictModuleWriteEvent, e); } } -static inline void redisModuleDelWrite(void *privdata) { - redisModuleEvents *e = (redisModuleEvents*)privdata; +static inline void redictModuleDelWrite(void *privdata) { + redictModuleEvents *e = (redictModuleEvents*)privdata; if (e->writing) { e->writing = 0; - RedisModule_EventLoopDel(e->fd, REDISMODULE_EVENTLOOP_WRITABLE); + RedictModule_EventLoopDel(e->fd, REDICTMODULE_EVENTLOOP_WRITABLE); } } -static inline void redisModuleStopTimer(void *privdata) { - redisModuleEvents *e = (redisModuleEvents*)privdata; +static inline void redictModuleStopTimer(void *privdata) { + redictModuleEvents *e = (redictModuleEvents*)privdata; if (e->timer_active) { - RedisModule_StopTimer(e->module_ctx, e->timer_id, NULL); + RedictModule_StopTimer(e->module_ctx, e->timer_id, NULL); } e->timer_active = 0; } -static inline void redisModuleCleanup(void *privdata) { - redisModuleEvents *e = (redisModuleEvents*)privdata; - redisModuleDelRead(privdata); - redisModuleDelWrite(privdata); - redisModuleStopTimer(privdata); +static inline void redictModuleCleanup(void *privdata) { + redictModuleEvents *e = (redictModuleEvents*)privdata; + redictModuleDelRead(privdata); + redictModuleDelWrite(privdata); + redictModuleStopTimer(privdata); hi_free(e); } -static inline void redisModuleTimeout(RedisModuleCtx *ctx, void *privdata) { +static inline void redictModuleTimeout(RedictModuleCtx *ctx, void *privdata) { (void) ctx; - redisModuleEvents *e = (redisModuleEvents*)privdata; + redictModuleEvents *e = (redictModuleEvents*)privdata; e->timer_active = 0; - redisAsyncHandleTimeout(e->context); + redictAsyncHandleTimeout(e->context); } -static inline void redisModuleSetTimeout(void *privdata, struct timeval tv) { - redisModuleEvents* e = (redisModuleEvents*)privdata; +static inline void redictModuleSetTimeout(void *privdata, struct timeval tv) { + redictModuleEvents* e = (redictModuleEvents*)privdata; - redisModuleStopTimer(privdata); + redictModuleStopTimer(privdata); mstime_t millis = tv.tv_sec * 1000 + tv.tv_usec / 1000.0; - e->timer_id = RedisModule_CreateTimer(e->module_ctx, millis, redisModuleTimeout, e); + e->timer_id = RedictModule_CreateTimer(e->module_ctx, millis, redictModuleTimeout, e); e->timer_active = 1; } -/* Check if Redis version is compatible with the adapter. */ -static inline int redisModuleCompatibilityCheck(void) { - if (!RedisModule_EventLoopAdd || - !RedisModule_EventLoopDel || - !RedisModule_CreateTimer || - !RedisModule_StopTimer) { - return REDIS_ERR; +/* Check if Redict is compatible with the adapter. */ +static inline int redictModuleCompatibilityCheck(void) { + if (!RedictModule_EventLoopAdd || + !RedictModule_EventLoopDel || + !RedictModule_CreateTimer || + !RedictModule_StopTimer) { + return REDICT_ERR; } - return REDIS_OK; + return REDICT_OK; } -static inline int redisModuleAttach(redisAsyncContext *ac, RedisModuleCtx *module_ctx) { - redisContext *c = &(ac->c); - redisModuleEvents *e; +static inline int redictModuleAttach(redictAsyncContext *ac, RedictModuleCtx *module_ctx) { + redictContext *c = &(ac->c); + redictModuleEvents *e; /* Nothing should be attached when something is already attached */ if (ac->ev.data != NULL) - return REDIS_ERR; + return REDICT_ERR; /* Create container for context and r/w events */ - e = (redisModuleEvents*)hi_malloc(sizeof(*e)); + e = (redictModuleEvents*)hi_malloc(sizeof(*e)); if (e == NULL) - return REDIS_ERR; + return REDICT_ERR; e->context = ac; e->module_ctx = module_ctx; @@ -141,15 +141,15 @@ static inline int redisModuleAttach(redisAsyncContext *ac, RedisModuleCtx *modul e->timer_active = 0; /* Register functions to start/stop listening for events */ - ac->ev.addRead = redisModuleAddRead; - ac->ev.delRead = redisModuleDelRead; - ac->ev.addWrite = redisModuleAddWrite; - ac->ev.delWrite = redisModuleDelWrite; - ac->ev.cleanup = redisModuleCleanup; - ac->ev.scheduleTimer = redisModuleSetTimeout; + ac->ev.addRead = redictModuleAddRead; + ac->ev.delRead = redictModuleDelRead; + ac->ev.addWrite = redictModuleAddWrite; + ac->ev.delWrite = redictModuleDelWrite; + ac->ev.cleanup = redictModuleCleanup; + ac->ev.scheduleTimer = redictModuleSetTimeout; ac->ev.data = e; - return REDIS_OK; + return REDICT_OK; } #endif diff --git a/alloc.c b/alloc.c index 294969b..342192b 100644 --- a/alloc.c +++ b/alloc.c @@ -14,7 +14,7 @@ #include #include -hiredisAllocFuncs hiredisAllocFns = { +hiredictAllocFuncs hiredictAllocFns = { .mallocFn = malloc, .callocFn = calloc, .reallocFn = realloc, @@ -22,18 +22,18 @@ hiredisAllocFuncs hiredisAllocFns = { .freeFn = free, }; -/* Override hiredis' allocators with ones supplied by the user */ -hiredisAllocFuncs hiredisSetAllocators(hiredisAllocFuncs *override) { - hiredisAllocFuncs orig = hiredisAllocFns; +/* Override hiredict' allocators with ones supplied by the user */ +hiredictAllocFuncs hiredictSetAllocators(hiredictAllocFuncs *override) { + hiredictAllocFuncs orig = hiredictAllocFns; - hiredisAllocFns = *override; + hiredictAllocFns = *override; return orig; } /* Reset allocators to use libc defaults */ -void hiredisResetAllocators(void) { - hiredisAllocFns = (hiredisAllocFuncs) { +void hiredictResetAllocators(void) { + hiredictAllocFns = (hiredictAllocFuncs) { .mallocFn = malloc, .callocFn = calloc, .reallocFn = realloc, @@ -45,7 +45,7 @@ void hiredisResetAllocators(void) { #ifdef _WIN32 void *hi_malloc(size_t size) { - return hiredisAllocFns.mallocFn(size); + return hiredictAllocFns.mallocFn(size); } void *hi_calloc(size_t nmemb, size_t size) { @@ -53,19 +53,19 @@ void *hi_calloc(size_t nmemb, size_t size) { if (SIZE_MAX / size < nmemb) return NULL; - return hiredisAllocFns.callocFn(nmemb, size); + return hiredictAllocFns.callocFn(nmemb, size); } void *hi_realloc(void *ptr, size_t size) { - return hiredisAllocFns.reallocFn(ptr, size); + return hiredictAllocFns.reallocFn(ptr, size); } char *hi_strdup(const char *str) { - return hiredisAllocFns.strdupFn(str); + return hiredictAllocFns.strdupFn(str); } void hi_free(void *ptr) { - hiredisAllocFns.freeFn(ptr); + hiredictAllocFns.freeFn(ptr); } #endif diff --git a/alloc.h b/alloc.h index 5d0b7cf..e24ae5f 100644 --- a/alloc.h +++ b/alloc.h @@ -9,8 +9,8 @@ * */ -#ifndef HIREDIS_ALLOC_H -#define HIREDIS_ALLOC_H +#ifndef HIREDICT_ALLOC_H +#define HIREDICT_ALLOC_H #include /* for size_t */ #include @@ -20,24 +20,24 @@ extern "C" { #endif /* Structure pointing to our actually configured allocators */ -typedef struct hiredisAllocFuncs { +typedef struct hiredictAllocFuncs { void *(*mallocFn)(size_t); void *(*callocFn)(size_t,size_t); void *(*reallocFn)(void*,size_t); char *(*strdupFn)(const char*); void (*freeFn)(void*); -} hiredisAllocFuncs; +} hiredictAllocFuncs; -hiredisAllocFuncs hiredisSetAllocators(hiredisAllocFuncs *ha); -void hiredisResetAllocators(void); +hiredictAllocFuncs hiredictSetAllocators(hiredictAllocFuncs *ha); +void hiredictResetAllocators(void); #ifndef _WIN32 -/* Hiredis' configured allocator function pointer struct */ -extern hiredisAllocFuncs hiredisAllocFns; +/* Hiredict' configured allocator function pointer struct */ +extern hiredictAllocFuncs hiredictAllocFns; static inline void *hi_malloc(size_t size) { - return hiredisAllocFns.mallocFn(size); + return hiredictAllocFns.mallocFn(size); } static inline void *hi_calloc(size_t nmemb, size_t size) { @@ -45,19 +45,19 @@ static inline void *hi_calloc(size_t nmemb, size_t size) { if (SIZE_MAX / size < nmemb) return NULL; - return hiredisAllocFns.callocFn(nmemb, size); + return hiredictAllocFns.callocFn(nmemb, size); } static inline void *hi_realloc(void *ptr, size_t size) { - return hiredisAllocFns.reallocFn(ptr, size); + return hiredictAllocFns.reallocFn(ptr, size); } static inline char *hi_strdup(const char *str) { - return hiredisAllocFns.strdupFn(str); + return hiredictAllocFns.strdupFn(str); } static inline void hi_free(void *ptr) { - hiredisAllocFns.freeFn(ptr); + hiredictAllocFns.freeFn(ptr); } #else @@ -74,4 +74,4 @@ void hi_free(void *ptr); } #endif -#endif /* HIREDIS_ALLOC_H */ +#endif /* HIREDICT_ALLOC_H */ diff --git a/appveyor.yml b/appveyor.yml index 3e10ba4..6791923 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -# Appveyor configuration file for CI build of hiredis on Windows (under Cygwin) +# Appveyor configuration file for CI build of hiredict on Windows (under Cygwin) environment: matrix: diff --git a/async.c b/async.c index 5595bca..2363092 100644 --- a/async.c +++ b/async.c @@ -34,9 +34,9 @@ #define assert(e) (void)(e) #endif -/* Forward declarations of hiredis.c functions */ -int __redisAppendCommand(redisContext *c, const char *cmd, size_t len); -void __redisSetError(redisContext *c, int type, const char *str); +/* Forward declarations of hiredict.c functions */ +int __redictAppendCommand(redictContext *c, const char *cmd, size_t len); +void __redictSetError(redictContext *c, int type, const char *str); /* Functions managing dictionary of callbacks for pub/sub. */ static unsigned int callbackHash(const void *key) { @@ -46,7 +46,7 @@ static unsigned int callbackHash(const void *key) { static void *callbackValDup(void *privdata, const void *src) { ((void) privdata); - redisCallback *dup; + redictCallback *dup; dup = hi_malloc(sizeof(*dup)); if (dup == NULL) @@ -85,8 +85,8 @@ static dictType callbackDict = { callbackValDestructor }; -static redisAsyncContext *redisAsyncInitialize(redisContext *c) { - redisAsyncContext *ac; +static redictAsyncContext *redictAsyncInitialize(redictContext *c) { + redictAsyncContext *ac; dict *channels = NULL, *patterns = NULL; channels = dictCreate(&callbackDict,NULL); @@ -97,16 +97,16 @@ static redisAsyncContext *redisAsyncInitialize(redisContext *c) { if (patterns == NULL) goto oom; - ac = hi_realloc(c,sizeof(redisAsyncContext)); + ac = hi_realloc(c,sizeof(redictAsyncContext)); if (ac == NULL) goto oom; c = &(ac->c); - /* The regular connect functions will always set the flag REDIS_CONNECTED. + /* The regular connect functions will always set the flag REDICT_CONNECTED. * For the async API, we want to wait until the first write event is * received up before setting this flag, so reset it here. */ - c->flags &= ~REDIS_CONNECTED; + c->flags &= ~REDICT_CONNECTED; ac->err = 0; ac->errstr = NULL; @@ -141,81 +141,81 @@ oom: } /* We want the error field to be accessible directly instead of requiring - * an indirection to the redisContext struct. */ -static void __redisAsyncCopyError(redisAsyncContext *ac) { + * an indirection to the redictContext struct. */ +static void __redictAsyncCopyError(redictAsyncContext *ac) { if (!ac) return; - redisContext *c = &(ac->c); + redictContext *c = &(ac->c); ac->err = c->err; ac->errstr = c->errstr; } -redisAsyncContext *redisAsyncConnectWithOptions(const redisOptions *options) { - redisOptions myOptions = *options; - redisContext *c; - redisAsyncContext *ac; +redictAsyncContext *redictAsyncConnectWithOptions(const redictOptions *options) { + redictOptions myOptions = *options; + redictContext *c; + redictAsyncContext *ac; /* Clear any erroneously set sync callback and flag that we don't want to * use freeReplyObject by default. */ myOptions.push_cb = NULL; - myOptions.options |= REDIS_OPT_NO_PUSH_AUTOFREE; + myOptions.options |= REDICT_OPT_NO_PUSH_AUTOFREE; - myOptions.options |= REDIS_OPT_NONBLOCK; - c = redisConnectWithOptions(&myOptions); + myOptions.options |= REDICT_OPT_NONBLOCK; + c = redictConnectWithOptions(&myOptions); if (c == NULL) { return NULL; } - ac = redisAsyncInitialize(c); + ac = redictAsyncInitialize(c); if (ac == NULL) { - redisFree(c); + redictFree(c); return NULL; } /* Set any configured async push handler */ - redisAsyncSetPushCallback(ac, myOptions.async_push_cb); + redictAsyncSetPushCallback(ac, myOptions.async_push_cb); - __redisAsyncCopyError(ac); + __redictAsyncCopyError(ac); return ac; } -redisAsyncContext *redisAsyncConnect(const char *ip, int port) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, ip, port); - return redisAsyncConnectWithOptions(&options); +redictAsyncContext *redictAsyncConnect(const char *ip, int port) { + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, ip, port); + return redictAsyncConnectWithOptions(&options); } -redisAsyncContext *redisAsyncConnectBind(const char *ip, int port, +redictAsyncContext *redictAsyncConnectBind(const char *ip, int port, const char *source_addr) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, ip, port); + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, ip, port); options.endpoint.tcp.source_addr = source_addr; - return redisAsyncConnectWithOptions(&options); + return redictAsyncConnectWithOptions(&options); } -redisAsyncContext *redisAsyncConnectBindWithReuse(const char *ip, int port, +redictAsyncContext *redictAsyncConnectBindWithReuse(const char *ip, int port, const char *source_addr) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, ip, port); - options.options |= REDIS_OPT_REUSEADDR; + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, ip, port); + options.options |= REDICT_OPT_REUSEADDR; options.endpoint.tcp.source_addr = source_addr; - return redisAsyncConnectWithOptions(&options); + return redictAsyncConnectWithOptions(&options); } -redisAsyncContext *redisAsyncConnectUnix(const char *path) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_UNIX(&options, path); - return redisAsyncConnectWithOptions(&options); +redictAsyncContext *redictAsyncConnectUnix(const char *path) { + redictOptions options = {0}; + REDICT_OPTIONS_SET_UNIX(&options, path); + return redictAsyncConnectWithOptions(&options); } static int -redisAsyncSetConnectCallbackImpl(redisAsyncContext *ac, redisConnectCallback *fn, - redisConnectCallbackNC *fn_nc) +redictAsyncSetConnectCallbackImpl(redictAsyncContext *ac, redictConnectCallback *fn, + redictConnectCallbackNC *fn_nc) { /* If either are already set, this is an error */ if (ac->onConnect || ac->onConnectNC) - return REDIS_ERR; + return REDICT_ERR; if (fn) { ac->onConnect = fn; @@ -228,33 +228,33 @@ redisAsyncSetConnectCallbackImpl(redisAsyncContext *ac, redisConnectCallback *fn * library functions are already set. */ _EL_ADD_WRITE(ac); - return REDIS_OK; + return REDICT_OK; } -int redisAsyncSetConnectCallback(redisAsyncContext *ac, redisConnectCallback *fn) { - return redisAsyncSetConnectCallbackImpl(ac, fn, NULL); +int redictAsyncSetConnectCallback(redictAsyncContext *ac, redictConnectCallback *fn) { + return redictAsyncSetConnectCallbackImpl(ac, fn, NULL); } -int redisAsyncSetConnectCallbackNC(redisAsyncContext *ac, redisConnectCallbackNC *fn) { - return redisAsyncSetConnectCallbackImpl(ac, NULL, fn); +int redictAsyncSetConnectCallbackNC(redictAsyncContext *ac, redictConnectCallbackNC *fn) { + return redictAsyncSetConnectCallbackImpl(ac, NULL, fn); } -int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn) { +int redictAsyncSetDisconnectCallback(redictAsyncContext *ac, redictDisconnectCallback *fn) { if (ac->onDisconnect == NULL) { ac->onDisconnect = fn; - return REDIS_OK; + return REDICT_OK; } - return REDIS_ERR; + return REDICT_ERR; } /* Helper functions to push/shift callbacks */ -static int __redisPushCallback(redisCallbackList *list, redisCallback *source) { - redisCallback *cb; +static int __redictPushCallback(redictCallbackList *list, redictCallback *source) { + redictCallback *cb; /* Copy callback from stack to heap */ cb = hi_malloc(sizeof(*cb)); if (cb == NULL) - return REDIS_ERR_OOM; + return REDICT_ERR_OOM; if (source != NULL) { memcpy(cb,source,sizeof(*cb)); @@ -267,11 +267,11 @@ static int __redisPushCallback(redisCallbackList *list, redisCallback *source) { if (list->tail != NULL) list->tail->next = cb; list->tail = cb; - return REDIS_OK; + return REDICT_OK; } -static int __redisShiftCallback(redisCallbackList *list, redisCallback *target) { - redisCallback *cb = list->head; +static int __redictShiftCallback(redictCallbackList *list, redictCallback *target) { + redictCallback *cb = list->head; if (cb != NULL) { list->head = cb->next; if (cb == list->tail) @@ -281,41 +281,41 @@ static int __redisShiftCallback(redisCallbackList *list, redisCallback *target) if (target != NULL) memcpy(target,cb,sizeof(*cb)); hi_free(cb); - return REDIS_OK; + return REDICT_OK; } - return REDIS_ERR; + return REDICT_ERR; } -static void __redisRunCallback(redisAsyncContext *ac, redisCallback *cb, redisReply *reply) { - redisContext *c = &(ac->c); +static void __redictRunCallback(redictAsyncContext *ac, redictCallback *cb, redictReply *reply) { + redictContext *c = &(ac->c); if (cb->fn != NULL) { - c->flags |= REDIS_IN_CALLBACK; + c->flags |= REDICT_IN_CALLBACK; cb->fn(ac,reply,cb->privdata); - c->flags &= ~REDIS_IN_CALLBACK; + c->flags &= ~REDICT_IN_CALLBACK; } } -static void __redisRunPushCallback(redisAsyncContext *ac, redisReply *reply) { +static void __redictRunPushCallback(redictAsyncContext *ac, redictReply *reply) { if (ac->push_cb != NULL) { - ac->c.flags |= REDIS_IN_CALLBACK; + ac->c.flags |= REDICT_IN_CALLBACK; ac->push_cb(ac, reply); - ac->c.flags &= ~REDIS_IN_CALLBACK; + ac->c.flags &= ~REDICT_IN_CALLBACK; } } -static void __redisRunConnectCallback(redisAsyncContext *ac, int status) +static void __redictRunConnectCallback(redictAsyncContext *ac, int status) { if (ac->onConnect == NULL && ac->onConnectNC == NULL) return; - if (!(ac->c.flags & REDIS_IN_CALLBACK)) { - ac->c.flags |= REDIS_IN_CALLBACK; + if (!(ac->c.flags & REDICT_IN_CALLBACK)) { + ac->c.flags |= REDICT_IN_CALLBACK; if (ac->onConnect) { ac->onConnect(ac, status); } else { ac->onConnectNC(ac, status); } - ac->c.flags &= ~REDIS_IN_CALLBACK; + ac->c.flags &= ~REDICT_IN_CALLBACK; } else { /* already in callback */ if (ac->onConnect) { @@ -326,13 +326,13 @@ static void __redisRunConnectCallback(redisAsyncContext *ac, int status) } } -static void __redisRunDisconnectCallback(redisAsyncContext *ac, int status) +static void __redictRunDisconnectCallback(redictAsyncContext *ac, int status) { if (ac->onDisconnect) { - if (!(ac->c.flags & REDIS_IN_CALLBACK)) { - ac->c.flags |= REDIS_IN_CALLBACK; + if (!(ac->c.flags & REDICT_IN_CALLBACK)) { + ac->c.flags |= REDICT_IN_CALLBACK; ac->onDisconnect(ac, status); - ac->c.flags &= ~REDIS_IN_CALLBACK; + ac->c.flags &= ~REDICT_IN_CALLBACK; } else { /* already in callback */ ac->onDisconnect(ac, status); @@ -341,23 +341,23 @@ static void __redisRunDisconnectCallback(redisAsyncContext *ac, int status) } /* Helper function to free the context. */ -static void __redisAsyncFree(redisAsyncContext *ac) { - redisContext *c = &(ac->c); - redisCallback cb; +static void __redictAsyncFree(redictAsyncContext *ac) { + redictContext *c = &(ac->c); + redictCallback cb; dictIterator it; dictEntry *de; /* Execute pending callbacks with NULL reply. */ - while (__redisShiftCallback(&ac->replies,&cb) == REDIS_OK) - __redisRunCallback(ac,&cb,NULL); - while (__redisShiftCallback(&ac->sub.replies,&cb) == REDIS_OK) - __redisRunCallback(ac,&cb,NULL); + while (__redictShiftCallback(&ac->replies,&cb) == REDICT_OK) + __redictRunCallback(ac,&cb,NULL); + while (__redictShiftCallback(&ac->sub.replies,&cb) == REDICT_OK) + __redictRunCallback(ac,&cb,NULL); /* Run subscription callbacks with NULL reply */ if (ac->sub.channels) { dictInitIterator(&it,ac->sub.channels); while ((de = dictNext(&it)) != NULL) - __redisRunCallback(ac,dictGetEntryVal(de),NULL); + __redictRunCallback(ac,dictGetEntryVal(de),NULL); dictRelease(ac->sub.channels); } @@ -365,7 +365,7 @@ static void __redisAsyncFree(redisAsyncContext *ac) { if (ac->sub.patterns) { dictInitIterator(&it,ac->sub.patterns); while ((de = dictNext(&it)) != NULL) - __redisRunCallback(ac,dictGetEntryVal(de),NULL); + __redictRunCallback(ac,dictGetEntryVal(de),NULL); dictRelease(ac->sub.patterns); } @@ -373,13 +373,13 @@ static void __redisAsyncFree(redisAsyncContext *ac) { /* Signal event lib to clean up */ _EL_CLEANUP(ac); - /* Execute disconnect callback. When redisAsyncFree() initiated destroying - * this context, the status will always be REDIS_OK. */ - if (c->flags & REDIS_CONNECTED) { - int status = ac->err == 0 ? REDIS_OK : REDIS_ERR; - if (c->flags & REDIS_FREEING) - status = REDIS_OK; - __redisRunDisconnectCallback(ac, status); + /* Execute disconnect callback. When redictAsyncFree() initiated destroying + * this context, the status will always be REDICT_OK. */ + if (c->flags & REDICT_CONNECTED) { + int status = ac->err == 0 ? REDICT_OK : REDICT_ERR; + if (c->flags & REDICT_FREEING) + status = REDICT_OK; + __redictRunDisconnectCallback(ac, status); } if (ac->dataCleanup) { @@ -387,72 +387,72 @@ static void __redisAsyncFree(redisAsyncContext *ac) { } /* Cleanup self */ - redisFree(c); + redictFree(c); } /* Free the async context. When this function is called from a callback, - * control needs to be returned to redisProcessCallbacks() before actual + * control needs to be returned to redictProcessCallbacks() before actual * free'ing. To do so, a flag is set on the context which is picked up by - * redisProcessCallbacks(). Otherwise, the context is immediately free'd. */ -void redisAsyncFree(redisAsyncContext *ac) { + * redictProcessCallbacks(). Otherwise, the context is immediately free'd. */ +void redictAsyncFree(redictAsyncContext *ac) { if (ac == NULL) return; - redisContext *c = &(ac->c); + redictContext *c = &(ac->c); - c->flags |= REDIS_FREEING; - if (!(c->flags & REDIS_IN_CALLBACK)) - __redisAsyncFree(ac); + c->flags |= REDICT_FREEING; + if (!(c->flags & REDICT_IN_CALLBACK)) + __redictAsyncFree(ac); } /* Helper function to make the disconnect happen and clean up. */ -void __redisAsyncDisconnect(redisAsyncContext *ac) { - redisContext *c = &(ac->c); +void __redictAsyncDisconnect(redictAsyncContext *ac) { + redictContext *c = &(ac->c); /* Make sure error is accessible if there is any */ - __redisAsyncCopyError(ac); + __redictAsyncCopyError(ac); if (ac->err == 0) { /* For clean disconnects, there should be no pending callbacks. */ - int ret = __redisShiftCallback(&ac->replies,NULL); - assert(ret == REDIS_ERR); + int ret = __redictShiftCallback(&ac->replies,NULL); + assert(ret == REDICT_ERR); } else { /* Disconnection is caused by an error, make sure that pending * callbacks cannot call new commands. */ - c->flags |= REDIS_DISCONNECTING; + c->flags |= REDICT_DISCONNECTING; } /* cleanup event library on disconnect. * this is safe to call multiple times */ _EL_CLEANUP(ac); - /* For non-clean disconnects, __redisAsyncFree() will execute pending + /* For non-clean disconnects, __redictAsyncFree() will execute pending * callbacks with a NULL-reply. */ - if (!(c->flags & REDIS_NO_AUTO_FREE)) { - __redisAsyncFree(ac); + if (!(c->flags & REDICT_NO_AUTO_FREE)) { + __redictAsyncFree(ac); } } -/* Tries to do a clean disconnect from Redis, meaning it stops new commands +/* Tries to do a clean disconnect from Redict, meaning it stops new commands * from being issued, but tries to flush the output buffer and execute * callbacks for all remaining replies. When this function is called from a * callback, there might be more replies and we can safely defer disconnecting - * to redisProcessCallbacks(). Otherwise, we can only disconnect immediately + * to redictProcessCallbacks(). Otherwise, we can only disconnect immediately * when there are no pending callbacks. */ -void redisAsyncDisconnect(redisAsyncContext *ac) { - redisContext *c = &(ac->c); - c->flags |= REDIS_DISCONNECTING; +void redictAsyncDisconnect(redictAsyncContext *ac) { + redictContext *c = &(ac->c); + c->flags |= REDICT_DISCONNECTING; /** unset the auto-free flag here, because disconnect undoes this */ - c->flags &= ~REDIS_NO_AUTO_FREE; - if (!(c->flags & REDIS_IN_CALLBACK) && ac->replies.head == NULL) - __redisAsyncDisconnect(ac); + c->flags &= ~REDICT_NO_AUTO_FREE; + if (!(c->flags & REDICT_IN_CALLBACK) && ac->replies.head == NULL) + __redictAsyncDisconnect(ac); } -static int __redisGetSubscribeCallback(redisAsyncContext *ac, redisReply *reply, redisCallback *dstcb) { - redisContext *c = &(ac->c); +static int __redictGetSubscribeCallback(redictAsyncContext *ac, redictReply *reply, redictCallback *dstcb) { + redictContext *c = &(ac->c); dict *callbacks; - redisCallback *cb = NULL; + redictCallback *cb = NULL; dictEntry *de; int pvariant; char *stype; @@ -460,10 +460,10 @@ static int __redisGetSubscribeCallback(redisAsyncContext *ac, redisReply *reply, /* Match reply with the expected format of a pushed message. * The type and number of elements (3 to 4) are specified at: - * https://redis.io/topics/pubsub#format-of-pushed-messages */ - if ((reply->type == REDIS_REPLY_ARRAY && !(c->flags & REDIS_SUPPORTS_PUSH) && reply->elements >= 3) || - reply->type == REDIS_REPLY_PUSH) { - assert(reply->element[0]->type == REDIS_REPLY_STRING); + * TODO: documentation for pubsub#format-of-pushed-messages */ + if ((reply->type == REDICT_REPLY_ARRAY && !(c->flags & REDICT_SUPPORTS_PUSH) && reply->elements >= 3) || + reply->type == REDICT_REPLY_PUSH) { + assert(reply->element[0]->type == REDICT_REPLY_STRING); stype = reply->element[0]->str; pvariant = (tolower(stype[0]) == 'p') ? 1 : 0; @@ -473,7 +473,7 @@ static int __redisGetSubscribeCallback(redisAsyncContext *ac, redisReply *reply, callbacks = ac->sub.channels; /* Locate the right callback */ - if (reply->element[1]->type == REDIS_REPLY_STRING) { + if (reply->element[1]->type == REDICT_REPLY_STRING) { sname = sdsnewlen(reply->element[1]->str,reply->element[1]->len); if (sname == NULL) goto oom; @@ -496,7 +496,7 @@ static int __redisGetSubscribeCallback(redisAsyncContext *ac, redisReply *reply, /* If this was the last unsubscribe message, revert to * non-subscribe mode. */ - assert(reply->element[2]->type == REDIS_REPLY_INTEGER); + assert(reply->element[2]->type == REDICT_REPLY_INTEGER); /* Unset subscribed flag only when no pipelined pending subscribe * or pending unsubscribe replies. */ @@ -504,36 +504,36 @@ static int __redisGetSubscribeCallback(redisAsyncContext *ac, redisReply *reply, && dictSize(ac->sub.channels) == 0 && dictSize(ac->sub.patterns) == 0 && ac->sub.pending_unsubs == 0) { - c->flags &= ~REDIS_SUBSCRIBED; + c->flags &= ~REDICT_SUBSCRIBED; /* Move ongoing regular command callbacks. */ - redisCallback cb; - while (__redisShiftCallback(&ac->sub.replies,&cb) == REDIS_OK) { - __redisPushCallback(&ac->replies,&cb); + redictCallback cb; + while (__redictShiftCallback(&ac->sub.replies,&cb) == REDICT_OK) { + __redictPushCallback(&ac->replies,&cb); } } } sdsfree(sname); } else { /* Shift callback for pending command in subscribed context. */ - __redisShiftCallback(&ac->sub.replies,dstcb); + __redictShiftCallback(&ac->sub.replies,dstcb); } - return REDIS_OK; + return REDICT_OK; oom: - __redisSetError(&(ac->c), REDIS_ERR_OOM, "Out of memory"); - __redisAsyncCopyError(ac); - return REDIS_ERR; + __redictSetError(&(ac->c), REDICT_ERR_OOM, "Out of memory"); + __redictAsyncCopyError(ac); + return REDICT_ERR; } -#define redisIsSpontaneousPushReply(r) \ - (redisIsPushReply(r) && !redisIsSubscribeReply(r)) +#define redictIsSpontaneousPushReply(r) \ + (redictIsPushReply(r) && !redictIsSubscribeReply(r)) -static int redisIsSubscribeReply(redisReply *reply) { +static int redictIsSubscribeReply(redictReply *reply) { char *str; size_t len, off; /* We will always have at least one string with the subscribe/message type */ - if (reply->elements < 1 || reply->element[0]->type != REDIS_REPLY_STRING || + if (reply->elements < 1 || reply->element[0]->type != REDICT_REPLY_STRING || reply->element[0]->len < sizeof("message") - 1) { return 0; @@ -549,18 +549,18 @@ static int redisIsSubscribeReply(redisReply *reply) { !strncasecmp(str, "unsubscribe", len); } -void redisProcessCallbacks(redisAsyncContext *ac) { - redisContext *c = &(ac->c); +void redictProcessCallbacks(redictAsyncContext *ac) { + redictContext *c = &(ac->c); void *reply = NULL; int status; - while((status = redisGetReply(c,&reply)) == REDIS_OK) { + while((status = redictGetReply(c,&reply)) == REDICT_OK) { if (reply == NULL) { /* When the connection is being disconnected and there are * no more replies, this is the cue to really disconnect. */ - if (c->flags & REDIS_DISCONNECTING && sdslen(c->obuf) == 0 + if (c->flags & REDICT_DISCONNECTING && sdslen(c->obuf) == 0 && ac->replies.head == NULL) { - __redisAsyncDisconnect(ac); + __redictAsyncDisconnect(ac); return; } /* When the connection is not being disconnected, simply stop @@ -569,22 +569,22 @@ void redisProcessCallbacks(redisAsyncContext *ac) { } /* Keep track of push message support for subscribe handling */ - if (redisIsPushReply(reply)) c->flags |= REDIS_SUPPORTS_PUSH; + if (redictIsPushReply(reply)) c->flags |= REDICT_SUPPORTS_PUSH; /* Send any non-subscribe related PUSH messages to our PUSH handler * while allowing subscribe related PUSH messages to pass through. * This allows existing code to be backward compatible and work in * either RESP2 or RESP3 mode. */ - if (redisIsSpontaneousPushReply(reply)) { - __redisRunPushCallback(ac, reply); + if (redictIsSpontaneousPushReply(reply)) { + __redictRunPushCallback(ac, reply); c->reader->fn->freeObject(reply); continue; } /* Even if the context is subscribed, pending regular * callbacks will get a reply before pub/sub messages arrive. */ - redisCallback cb = {NULL, NULL, 0, 0, NULL}; - if (__redisShiftCallback(&ac->replies,&cb) != REDIS_OK) { + redictCallback cb = {NULL, NULL, 0, 0, NULL}; + if (__redictShiftCallback(&ac->replies,&cb) != REDICT_OK) { /* * A spontaneous reply in a not-subscribed context can be the error * reply that is sent when a new connection exceeds the maximum @@ -600,28 +600,28 @@ void redisProcessCallbacks(redisAsyncContext *ac) { * In this case we also want to close the connection, and have the * user wait until the server is ready to take our request. */ - if (((redisReply*)reply)->type == REDIS_REPLY_ERROR) { - c->err = REDIS_ERR_OTHER; - snprintf(c->errstr,sizeof(c->errstr),"%s",((redisReply*)reply)->str); + if (((redictReply*)reply)->type == REDICT_REPLY_ERROR) { + c->err = REDICT_ERR_OTHER; + snprintf(c->errstr,sizeof(c->errstr),"%s",((redictReply*)reply)->str); c->reader->fn->freeObject(reply); - __redisAsyncDisconnect(ac); + __redictAsyncDisconnect(ac); return; } /* No more regular callbacks and no errors, the context *must* be subscribed. */ - assert(c->flags & REDIS_SUBSCRIBED); - if (c->flags & REDIS_SUBSCRIBED) - __redisGetSubscribeCallback(ac,reply,&cb); + assert(c->flags & REDICT_SUBSCRIBED); + if (c->flags & REDICT_SUBSCRIBED) + __redictGetSubscribeCallback(ac,reply,&cb); } if (cb.fn != NULL) { - __redisRunCallback(ac,&cb,reply); - if (!(c->flags & REDIS_NO_AUTO_FREE_REPLIES)){ + __redictRunCallback(ac,&cb,reply); + if (!(c->flags & REDICT_NO_AUTO_FREE_REPLIES)){ c->reader->fn->freeObject(reply); } - /* Proceed with free'ing when redisAsyncFree() was called. */ - if (c->flags & REDIS_FREEING) { - __redisAsyncFree(ac); + /* Proceed with free'ing when redictAsyncFree() was called. */ + if (c->flags & REDICT_FREEING) { + __redictAsyncFree(ac); return; } } else { @@ -633,99 +633,99 @@ void redisProcessCallbacks(redisAsyncContext *ac) { } /* If in monitor mode, repush the callback */ - if (c->flags & REDIS_MONITORING) { - __redisPushCallback(&ac->replies,&cb); + if (c->flags & REDICT_MONITORING) { + __redictPushCallback(&ac->replies,&cb); } } /* Disconnect when there was an error reading the reply */ - if (status != REDIS_OK) - __redisAsyncDisconnect(ac); + if (status != REDICT_OK) + __redictAsyncDisconnect(ac); } -static void __redisAsyncHandleConnectFailure(redisAsyncContext *ac) { - __redisRunConnectCallback(ac, REDIS_ERR); - __redisAsyncDisconnect(ac); +static void __redictAsyncHandleConnectFailure(redictAsyncContext *ac) { + __redictRunConnectCallback(ac, REDICT_ERR); + __redictAsyncDisconnect(ac); } /* Internal helper function to detect socket status the first time a read or * write event fires. When connecting was not successful, the connect callback - * is called with a REDIS_ERR status and the context is free'd. */ -static int __redisAsyncHandleConnect(redisAsyncContext *ac) { + * is called with a REDICT_ERR status and the context is free'd. */ +static int __redictAsyncHandleConnect(redictAsyncContext *ac) { int completed = 0; - redisContext *c = &(ac->c); + redictContext *c = &(ac->c); - if (redisCheckConnectDone(c, &completed) == REDIS_ERR) { + if (redictCheckConnectDone(c, &completed) == REDICT_ERR) { /* Error! */ - if (redisCheckSocketError(c) == REDIS_ERR) - __redisAsyncCopyError(ac); - __redisAsyncHandleConnectFailure(ac); - return REDIS_ERR; + if (redictCheckSocketError(c) == REDICT_ERR) + __redictAsyncCopyError(ac); + __redictAsyncHandleConnectFailure(ac); + return REDICT_ERR; } else if (completed == 1) { /* connected! */ - if (c->connection_type == REDIS_CONN_TCP && - redisSetTcpNoDelay(c) == REDIS_ERR) { - __redisAsyncHandleConnectFailure(ac); - return REDIS_ERR; + if (c->connection_type == REDICT_CONN_TCP && + redictSetTcpNoDelay(c) == REDICT_ERR) { + __redictAsyncHandleConnectFailure(ac); + return REDICT_ERR; } /* flag us as fully connect, but allow the callback * to disconnect. For that reason, permit the function * to delete the context here after callback return. */ - c->flags |= REDIS_CONNECTED; - __redisRunConnectCallback(ac, REDIS_OK); - if ((ac->c.flags & REDIS_DISCONNECTING)) { - redisAsyncDisconnect(ac); - return REDIS_ERR; - } else if ((ac->c.flags & REDIS_FREEING)) { - redisAsyncFree(ac); - return REDIS_ERR; + c->flags |= REDICT_CONNECTED; + __redictRunConnectCallback(ac, REDICT_OK); + if ((ac->c.flags & REDICT_DISCONNECTING)) { + redictAsyncDisconnect(ac); + return REDICT_ERR; + } else if ((ac->c.flags & REDICT_FREEING)) { + redictAsyncFree(ac); + return REDICT_ERR; } - return REDIS_OK; + return REDICT_OK; } else { - return REDIS_OK; + return REDICT_OK; } } -void redisAsyncRead(redisAsyncContext *ac) { - redisContext *c = &(ac->c); +void redictAsyncRead(redictAsyncContext *ac) { + redictContext *c = &(ac->c); - if (redisBufferRead(c) == REDIS_ERR) { - __redisAsyncDisconnect(ac); + if (redictBufferRead(c) == REDICT_ERR) { + __redictAsyncDisconnect(ac); } else { /* Always re-schedule reads */ _EL_ADD_READ(ac); - redisProcessCallbacks(ac); + redictProcessCallbacks(ac); } } /* This function should be called when the socket is readable. * It processes all replies that can be read and executes their callbacks. */ -void redisAsyncHandleRead(redisAsyncContext *ac) { - redisContext *c = &(ac->c); +void redictAsyncHandleRead(redictAsyncContext *ac) { + redictContext *c = &(ac->c); /* must not be called from a callback */ - assert(!(c->flags & REDIS_IN_CALLBACK)); + assert(!(c->flags & REDICT_IN_CALLBACK)); - if (!(c->flags & REDIS_CONNECTED)) { + if (!(c->flags & REDICT_CONNECTED)) { /* Abort connect was not successful. */ - if (__redisAsyncHandleConnect(ac) != REDIS_OK) + if (__redictAsyncHandleConnect(ac) != REDICT_OK) return; /* Try again later when the context is still not connected. */ - if (!(c->flags & REDIS_CONNECTED)) + if (!(c->flags & REDICT_CONNECTED)) return; } c->funcs->async_read(ac); } -void redisAsyncWrite(redisAsyncContext *ac) { - redisContext *c = &(ac->c); +void redictAsyncWrite(redictAsyncContext *ac) { + redictContext *c = &(ac->c); int done = 0; - if (redisBufferWrite(c,&done) == REDIS_ERR) { - __redisAsyncDisconnect(ac); + if (redictBufferWrite(c,&done) == REDICT_ERR) { + __redictAsyncDisconnect(ac); } else { /* Continue writing when not done, stop writing otherwise */ if (!done) @@ -738,30 +738,30 @@ void redisAsyncWrite(redisAsyncContext *ac) { } } -void redisAsyncHandleWrite(redisAsyncContext *ac) { - redisContext *c = &(ac->c); +void redictAsyncHandleWrite(redictAsyncContext *ac) { + redictContext *c = &(ac->c); /* must not be called from a callback */ - assert(!(c->flags & REDIS_IN_CALLBACK)); + assert(!(c->flags & REDICT_IN_CALLBACK)); - if (!(c->flags & REDIS_CONNECTED)) { + if (!(c->flags & REDICT_CONNECTED)) { /* Abort connect was not successful. */ - if (__redisAsyncHandleConnect(ac) != REDIS_OK) + if (__redictAsyncHandleConnect(ac) != REDICT_OK) return; /* Try again later when the context is still not connected. */ - if (!(c->flags & REDIS_CONNECTED)) + if (!(c->flags & REDICT_CONNECTED)) return; } c->funcs->async_write(ac); } -void redisAsyncHandleTimeout(redisAsyncContext *ac) { - redisContext *c = &(ac->c); - redisCallback cb; +void redictAsyncHandleTimeout(redictAsyncContext *ac) { + redictContext *c = &(ac->c); + redictCallback cb; /* must not be called from a callback */ - assert(!(c->flags & REDIS_IN_CALLBACK)); + assert(!(c->flags & REDICT_IN_CALLBACK)); - if ((c->flags & REDIS_CONNECTED)) { + if ((c->flags & REDICT_CONNECTED)) { if (ac->replies.head == NULL && ac->sub.replies.head == NULL) { /* Nothing to do - just an idle timeout */ return; @@ -775,23 +775,23 @@ void redisAsyncHandleTimeout(redisAsyncContext *ac) { } if (!c->err) { - __redisSetError(c, REDIS_ERR_TIMEOUT, "Timeout"); - __redisAsyncCopyError(ac); + __redictSetError(c, REDICT_ERR_TIMEOUT, "Timeout"); + __redictAsyncCopyError(ac); } - if (!(c->flags & REDIS_CONNECTED)) { - __redisRunConnectCallback(ac, REDIS_ERR); + if (!(c->flags & REDICT_CONNECTED)) { + __redictRunConnectCallback(ac, REDICT_ERR); } - while (__redisShiftCallback(&ac->replies, &cb) == REDIS_OK) { - __redisRunCallback(ac, &cb, NULL); + while (__redictShiftCallback(&ac->replies, &cb) == REDICT_OK) { + __redictRunCallback(ac, &cb, NULL); } /** * TODO: Don't automatically sever the connection, * rather, allow to ignore responses before the queue is clear */ - __redisAsyncDisconnect(ac); + __redictAsyncDisconnect(ac); } /* Sets a pointer to the first argument and its length starting at p. Returns @@ -810,16 +810,16 @@ static const char *nextArgument(const char *start, const char **str, size_t *len return p+2+(*len)+2; } -/* Helper function for the redisAsyncCommand* family of functions. Writes a +/* Helper function for the redictAsyncCommand* family of functions. Writes a * formatted command to the output buffer and registers the provided callback * function with the context. */ -static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *cmd, size_t len) { - redisContext *c = &(ac->c); - redisCallback cb; +static int __redictAsyncCommand(redictAsyncContext *ac, redictCallbackFn *fn, void *privdata, const char *cmd, size_t len) { + redictContext *c = &(ac->c); + redictCallback cb; struct dict *cbdict; dictIterator it; dictEntry *de; - redisCallback *existcb; + redictCallback *existcb; int pvariant, hasnext; const char *cstr, *astr; size_t clen, alen; @@ -828,7 +828,7 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void int ret; /* Don't accept new commands when the connection is about to be closed. */ - if (c->flags & (REDIS_DISCONNECTING | REDIS_FREEING)) return REDIS_ERR; + if (c->flags & (REDICT_DISCONNECTING | REDICT_FREEING)) return REDICT_ERR; /* Setup callback */ cb.fn = fn; @@ -845,7 +845,7 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void clen -= pvariant; if (hasnext && strncasecmp(cstr,"subscribe\r\n",11) == 0) { - c->flags |= REDIS_SUBSCRIBED; + c->flags |= REDICT_SUBSCRIBED; /* Add every channel/pattern to the list of subscription callbacks. */ while ((p = nextArgument(p,&astr,&alen)) != NULL) { @@ -872,7 +872,7 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void } else if (strncasecmp(cstr,"unsubscribe\r\n",13) == 0) { /* It is only useful to call (P)UNSUBSCRIBE when the context is * subscribed to one or more channels or patterns. */ - if (!(c->flags & REDIS_SUBSCRIBED)) return REDIS_ERR; + if (!(c->flags & REDICT_SUBSCRIBED)) return REDICT_ERR; if (pvariant) cbdict = ac->sub.patterns; @@ -924,85 +924,85 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void * should not append a callback function for this command. */ } else if (strncasecmp(cstr,"monitor\r\n",9) == 0) { /* Set monitor flag and push callback */ - c->flags |= REDIS_MONITORING; - if (__redisPushCallback(&ac->replies,&cb) != REDIS_OK) + c->flags |= REDICT_MONITORING; + if (__redictPushCallback(&ac->replies,&cb) != REDICT_OK) goto oom; } else { - if (c->flags & REDIS_SUBSCRIBED) { - if (__redisPushCallback(&ac->sub.replies,&cb) != REDIS_OK) + if (c->flags & REDICT_SUBSCRIBED) { + if (__redictPushCallback(&ac->sub.replies,&cb) != REDICT_OK) goto oom; } else { - if (__redisPushCallback(&ac->replies,&cb) != REDIS_OK) + if (__redictPushCallback(&ac->replies,&cb) != REDICT_OK) goto oom; } } - __redisAppendCommand(c,cmd,len); + __redictAppendCommand(c,cmd,len); /* Always schedule a write when the write buffer is non-empty */ _EL_ADD_WRITE(ac); - return REDIS_OK; + return REDICT_OK; oom: - __redisSetError(&(ac->c), REDIS_ERR_OOM, "Out of memory"); - __redisAsyncCopyError(ac); - return REDIS_ERR; + __redictSetError(&(ac->c), REDICT_ERR_OOM, "Out of memory"); + __redictAsyncCopyError(ac); + return REDICT_ERR; } -int redisvAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, va_list ap) { +int redictvAsyncCommand(redictAsyncContext *ac, redictCallbackFn *fn, void *privdata, const char *format, va_list ap) { char *cmd; int len; int status; - len = redisvFormatCommand(&cmd,format,ap); + len = redictvFormatCommand(&cmd,format,ap); /* We don't want to pass -1 or -2 to future functions as a length. */ if (len < 0) - return REDIS_ERR; + return REDICT_ERR; - status = __redisAsyncCommand(ac,fn,privdata,cmd,len); + status = __redictAsyncCommand(ac,fn,privdata,cmd,len); hi_free(cmd); return status; } -int redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, ...) { +int redictAsyncCommand(redictAsyncContext *ac, redictCallbackFn *fn, void *privdata, const char *format, ...) { va_list ap; int status; va_start(ap,format); - status = redisvAsyncCommand(ac,fn,privdata,format,ap); + status = redictvAsyncCommand(ac,fn,privdata,format,ap); va_end(ap); return status; } -int redisAsyncCommandArgv(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, int argc, const char **argv, const size_t *argvlen) { +int redictAsyncCommandArgv(redictAsyncContext *ac, redictCallbackFn *fn, void *privdata, int argc, const char **argv, const size_t *argvlen) { sds cmd; long long len; int status; - len = redisFormatSdsCommandArgv(&cmd,argc,argv,argvlen); + len = redictFormatSdsCommandArgv(&cmd,argc,argv,argvlen); if (len < 0) - return REDIS_ERR; - status = __redisAsyncCommand(ac,fn,privdata,cmd,len); + return REDICT_ERR; + status = __redictAsyncCommand(ac,fn,privdata,cmd,len); sdsfree(cmd); return status; } -int redisAsyncFormattedCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *cmd, size_t len) { - int status = __redisAsyncCommand(ac,fn,privdata,cmd,len); +int redictAsyncFormattedCommand(redictAsyncContext *ac, redictCallbackFn *fn, void *privdata, const char *cmd, size_t len) { + int status = __redictAsyncCommand(ac,fn,privdata,cmd,len); return status; } -redisAsyncPushFn *redisAsyncSetPushCallback(redisAsyncContext *ac, redisAsyncPushFn *fn) { - redisAsyncPushFn *old = ac->push_cb; +redictAsyncPushFn *redictAsyncSetPushCallback(redictAsyncContext *ac, redictAsyncPushFn *fn) { + redictAsyncPushFn *old = ac->push_cb; ac->push_cb = fn; return old; } -int redisAsyncSetTimeout(redisAsyncContext *ac, struct timeval tv) { +int redictAsyncSetTimeout(redictAsyncContext *ac, struct timeval tv) { if (!ac->c.command_timeout) { ac->c.command_timeout = hi_calloc(1, sizeof(tv)); if (ac->c.command_timeout == NULL) { - __redisSetError(&ac->c, REDIS_ERR_OOM, "Out of memory"); - __redisAsyncCopyError(ac); - return REDIS_ERR; + __redictSetError(&ac->c, REDICT_ERR_OOM, "Out of memory"); + __redictAsyncCopyError(ac); + return REDICT_ERR; } } @@ -1012,5 +1012,5 @@ int redisAsyncSetTimeout(redisAsyncContext *ac, struct timeval tv) { *ac->c.command_timeout = tv; } - return REDIS_OK; + return REDICT_OK; } diff --git a/async.h b/async.h index 3244a98..527efa6 100644 --- a/async.h +++ b/async.h @@ -11,48 +11,48 @@ * */ -#ifndef __HIREDIS_ASYNC_H -#define __HIREDIS_ASYNC_H +#ifndef __HIREDICT_ASYNC_H +#define __HIREDICT_ASYNC_H #include "hiredict.h" #ifdef __cplusplus extern "C" { #endif -struct redisAsyncContext; /* need forward declaration of redisAsyncContext */ +struct redictAsyncContext; /* need forward declaration of redictAsyncContext */ struct dict; /* dictionary header is included in async.c */ /* Reply callback prototype and container */ -typedef void (redisCallbackFn)(struct redisAsyncContext*, void*, void*); -typedef struct redisCallback { - struct redisCallback *next; /* simple singly linked list */ - redisCallbackFn *fn; +typedef void (redictCallbackFn)(struct redictAsyncContext*, void*, void*); +typedef struct redictCallback { + struct redictCallback *next; /* simple singly linked list */ + redictCallbackFn *fn; int pending_subs; int unsubscribe_sent; void *privdata; -} redisCallback; +} redictCallback; /* List of callbacks for either regular replies or pub/sub */ -typedef struct redisCallbackList { - redisCallback *head, *tail; -} redisCallbackList; +typedef struct redictCallbackList { + redictCallback *head, *tail; +} redictCallbackList; /* Connection callback prototypes */ -typedef void (redisDisconnectCallback)(const struct redisAsyncContext*, int status); -typedef void (redisConnectCallback)(const struct redisAsyncContext*, int status); -typedef void (redisConnectCallbackNC)(struct redisAsyncContext *, int status); -typedef void(redisTimerCallback)(void *timer, void *privdata); +typedef void (redictDisconnectCallback)(const struct redictAsyncContext*, int status); +typedef void (redictConnectCallback)(const struct redictAsyncContext*, int status); +typedef void (redictConnectCallbackNC)(struct redictAsyncContext*, int status); +typedef void (redictTimerCallback)(void *timer, void *privdata); -/* Context for an async connection to Redis */ -typedef struct redisAsyncContext { +/* Context for an async connection to Redict */ +typedef struct redictAsyncContext { /* Hold the regular context, so it can be realloc'ed. */ - redisContext c; + redictContext c; /* Setup error flags so they can be used directly. */ int err; char *errstr; - /* Not used by hiredis */ + /* Not used by hiredict */ void *data; void (*dataCleanup)(void *privdata); @@ -71,15 +71,15 @@ typedef struct redisAsyncContext { } ev; /* 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; + * user request. The status is set accordingly (REDICT_OK, REDICT_ERR). */ + redictDisconnectCallback *onDisconnect; /* Called when the first write event was received. */ - redisConnectCallback *onConnect; - redisConnectCallbackNC *onConnectNC; + redictConnectCallback *onConnect; + redictConnectCallbackNC *onConnectNC; /* Regular command callbacks */ - redisCallbackList replies; + redictCallbackList replies; /* Address used for connect() */ struct sockaddr *saddr; @@ -87,45 +87,45 @@ typedef struct redisAsyncContext { /* Subscription callbacks */ struct { - redisCallbackList replies; + redictCallbackList replies; struct dict *channels; struct dict *patterns; int pending_unsubs; } sub; /* Any configured RESP3 PUSH handler */ - redisAsyncPushFn *push_cb; -} redisAsyncContext; - -/* Functions that proxy to hiredis */ -redisAsyncContext *redisAsyncConnectWithOptions(const redisOptions *options); -redisAsyncContext *redisAsyncConnect(const char *ip, int port); -redisAsyncContext *redisAsyncConnectBind(const char *ip, int port, const char *source_addr); -redisAsyncContext *redisAsyncConnectBindWithReuse(const char *ip, int port, + redictAsyncPushFn *push_cb; +} redictAsyncContext; + +/* Functions that proxy to hiredict */ +redictAsyncContext *redictAsyncConnectWithOptions(const redictOptions *options); +redictAsyncContext *redictAsyncConnect(const char *ip, int port); +redictAsyncContext *redictAsyncConnectBind(const char *ip, int port, const char *source_addr); +redictAsyncContext *redictAsyncConnectBindWithReuse(const char *ip, int port, const char *source_addr); -redisAsyncContext *redisAsyncConnectUnix(const char *path); -int redisAsyncSetConnectCallback(redisAsyncContext *ac, redisConnectCallback *fn); -int redisAsyncSetConnectCallbackNC(redisAsyncContext *ac, redisConnectCallbackNC *fn); -int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn); +redictAsyncContext *redictAsyncConnectUnix(const char *path); +int redictAsyncSetConnectCallback(redictAsyncContext *ac, redictConnectCallback *fn); +int redictAsyncSetConnectCallbackNC(redictAsyncContext *ac, redictConnectCallbackNC *fn); +int redictAsyncSetDisconnectCallback(redictAsyncContext *ac, redictDisconnectCallback *fn); -redisAsyncPushFn *redisAsyncSetPushCallback(redisAsyncContext *ac, redisAsyncPushFn *fn); -int redisAsyncSetTimeout(redisAsyncContext *ac, struct timeval tv); -void redisAsyncDisconnect(redisAsyncContext *ac); -void redisAsyncFree(redisAsyncContext *ac); +redictAsyncPushFn *redictAsyncSetPushCallback(redictAsyncContext *ac, redictAsyncPushFn *fn); +int redictAsyncSetTimeout(redictAsyncContext *ac, struct timeval tv); +void redictAsyncDisconnect(redictAsyncContext *ac); +void redictAsyncFree(redictAsyncContext *ac); /* Handle read/write events */ -void redisAsyncHandleRead(redisAsyncContext *ac); -void redisAsyncHandleWrite(redisAsyncContext *ac); -void redisAsyncHandleTimeout(redisAsyncContext *ac); -void redisAsyncRead(redisAsyncContext *ac); -void redisAsyncWrite(redisAsyncContext *ac); +void redictAsyncHandleRead(redictAsyncContext *ac); +void redictAsyncHandleWrite(redictAsyncContext *ac); +void redictAsyncHandleTimeout(redictAsyncContext *ac); +void redictAsyncRead(redictAsyncContext *ac); +void redictAsyncWrite(redictAsyncContext *ac); /* Command functions for an async context. Write the command to the * output buffer and register the provided callback. */ -int redisvAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, va_list ap); -int redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, ...); -int redisAsyncCommandArgv(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, int argc, const char **argv, const size_t *argvlen); -int redisAsyncFormattedCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *cmd, size_t len); +int redictvAsyncCommand(redictAsyncContext *ac, redictCallbackFn *fn, void *privdata, const char *format, va_list ap); +int redictAsyncCommand(redictAsyncContext *ac, redictCallbackFn *fn, void *privdata, const char *format, ...); +int redictAsyncCommandArgv(redictAsyncContext *ac, redictCallbackFn *fn, void *privdata, int argc, const char **argv, const size_t *argvlen); +int redictAsyncFormattedCommand(redictAsyncContext *ac, redictCallbackFn *fn, void *privdata, const char *cmd, size_t len); #ifdef __cplusplus } diff --git a/async_private.h b/async_private.h index 855ae96..c5a7e21 100644 --- a/async_private.h +++ b/async_private.h @@ -11,8 +11,8 @@ * */ -#ifndef __HIREDIS_ASYNC_PRIVATE_H -#define __HIREDIS_ASYNC_PRIVATE_H +#ifndef __HIREDICT_ASYNC_PRIVATE_H +#define __HIREDICT_ASYNC_PRIVATE_H #define _EL_ADD_READ(ctx) \ do { \ @@ -35,23 +35,23 @@ ctx->ev.cleanup = NULL; \ } while(0) -static inline void refreshTimeout(redisAsyncContext *ctx) { - #define REDIS_TIMER_ISSET(tvp) \ +static inline void refreshTimeout(redictAsyncContext *ctx) { + #define REDICT_TIMER_ISSET(tvp) \ (tvp && ((tvp)->tv_sec || (tvp)->tv_usec)) - #define REDIS_EL_TIMER(ac, tvp) \ - if ((ac)->ev.scheduleTimer && REDIS_TIMER_ISSET(tvp)) { \ + #define REDICT_EL_TIMER(ac, tvp) \ + if ((ac)->ev.scheduleTimer && REDICT_TIMER_ISSET(tvp)) { \ (ac)->ev.scheduleTimer((ac)->ev.data, *(tvp)); \ } - if (ctx->c.flags & REDIS_CONNECTED) { - REDIS_EL_TIMER(ctx, ctx->c.command_timeout); + if (ctx->c.flags & REDICT_CONNECTED) { + REDICT_EL_TIMER(ctx, ctx->c.command_timeout); } else { - REDIS_EL_TIMER(ctx, ctx->c.connect_timeout); + REDICT_EL_TIMER(ctx, ctx->c.connect_timeout); } } -void __redisAsyncDisconnect(redisAsyncContext *ac); -void redisProcessCallbacks(redisAsyncContext *ac); +void __redictAsyncDisconnect(redictAsyncContext *ac); +void redictProcessCallbacks(redictAsyncContext *ac); -#endif /* __HIREDIS_ASYNC_PRIVATE_H */ +#endif /* __HIREDICT_ASYNC_PRIVATE_H */ diff --git a/examples/example-ae.c b/examples/example-ae.c index 983ca9c..170d7b2 100644 --- a/examples/example-ae.c +++ b/examples/example-ae.c @@ -16,17 +16,17 @@ /* Put event loop in the global scope, so it can be explicitly stopped */ static aeEventLoop *loop; -void getCallback(redisAsyncContext *c, void *r, void *privdata) { - redisReply *reply = r; +void getCallback(redictAsyncContext *c, void *r, void *privdata) { + redictReply *reply = r; if (reply == NULL) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void connectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void connectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); aeStop(loop); return; @@ -35,8 +35,8 @@ void connectCallback(const redisAsyncContext *c, int status) { printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void disconnectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); aeStop(loop); return; @@ -49,7 +49,7 @@ void disconnectCallback(const redisAsyncContext *c, int status) { int main (int argc, char **argv) { signal(SIGPIPE, SIG_IGN); - redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); + redictAsyncContext *c = redictAsyncConnect("127.0.0.1", 6379); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); @@ -57,11 +57,11 @@ int main (int argc, char **argv) { } loop = aeCreateEventLoop(64); - redisAeAttach(loop, c); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictAeAttach(loop, c); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); aeMain(loop); return 0; } diff --git a/examples/example-glib.c b/examples/example-glib.c index 46aa550..97cf279 100644 --- a/examples/example-glib.c +++ b/examples/example-glib.c @@ -13,10 +13,10 @@ static GMainLoop *mainloop; static void -connect_cb (const redisAsyncContext *ac G_GNUC_UNUSED, +connect_cb (const redictAsyncContext *ac G_GNUC_UNUSED, int status) { - if (status != REDIS_OK) { + if (status != REDICT_OK) { g_printerr("Failed to connect: %s\n", ac->errstr); g_main_loop_quit(mainloop); } else { @@ -25,10 +25,10 @@ connect_cb (const redisAsyncContext *ac G_GNUC_UNUSED, } static void -disconnect_cb (const redisAsyncContext *ac G_GNUC_UNUSED, +disconnect_cb (const redictAsyncContext *ac G_GNUC_UNUSED, int status) { - if (status != REDIS_OK) { + if (status != REDICT_OK) { g_error("Failed to disconnect: %s", ac->errstr); } else { g_printerr("Disconnected...\n"); @@ -37,41 +37,41 @@ disconnect_cb (const redisAsyncContext *ac G_GNUC_UNUSED, } static void -command_cb(redisAsyncContext *ac, +command_cb(redictAsyncContext *ac, gpointer r, gpointer user_data G_GNUC_UNUSED) { - redisReply *reply = r; + redictReply *reply = r; if (reply) { g_print("REPLY: %s\n", reply->str); } - redisAsyncDisconnect(ac); + redictAsyncDisconnect(ac); } gint main (gint argc G_GNUC_UNUSED, gchar *argv[] G_GNUC_UNUSED) { - redisAsyncContext *ac; + redictAsyncContext *ac; GMainContext *context = NULL; GSource *source; - ac = redisAsyncConnect("127.0.0.1", 6379); + ac = redictAsyncConnect("127.0.0.1", 6379); if (ac->err) { g_printerr("%s\n", ac->errstr); exit(EXIT_FAILURE); } - source = redis_source_new(ac); + source = redict_source_new(ac); mainloop = g_main_loop_new(context, FALSE); g_source_attach(source, context); - redisAsyncSetConnectCallback(ac, connect_cb); - redisAsyncSetDisconnectCallback(ac, disconnect_cb); - redisAsyncCommand(ac, command_cb, NULL, "SET key 1234"); - redisAsyncCommand(ac, command_cb, NULL, "GET key"); + redictAsyncSetConnectCallback(ac, connect_cb); + redictAsyncSetDisconnectCallback(ac, disconnect_cb); + redictAsyncCommand(ac, command_cb, NULL, "SET key 1234"); + redictAsyncCommand(ac, command_cb, NULL, "GET key"); g_main_loop_run(mainloop); diff --git a/examples/example-ivykis.c b/examples/example-ivykis.c index 989fa12..8aa2570 100644 --- a/examples/example-ivykis.c +++ b/examples/example-ivykis.c @@ -13,25 +13,25 @@ #include #include -void getCallback(redisAsyncContext *c, void *r, void *privdata) { - redisReply *reply = r; +void getCallback(redictAsyncContext *c, void *r, void *privdata) { + redictReply *reply = r; if (reply == NULL) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void connectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void connectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void disconnectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } @@ -45,18 +45,18 @@ int main (int argc, char **argv) { iv_init(); - redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); + redictAsyncContext *c = redictAsyncConnect("127.0.0.1", 6379); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); return 1; } - redisIvykisAttach(c); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictIvykisAttach(c); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); iv_main(); diff --git a/examples/example-libev.c b/examples/example-libev.c index ade7ed1..b180674 100644 --- a/examples/example-libev.c +++ b/examples/example-libev.c @@ -13,25 +13,25 @@ #include #include -void getCallback(redisAsyncContext *c, void *r, void *privdata) { - redisReply *reply = r; +void getCallback(redictAsyncContext *c, void *r, void *privdata) { + redictReply *reply = r; if (reply == NULL) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void connectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void connectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void disconnectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } @@ -43,18 +43,18 @@ int main (int argc, char **argv) { signal(SIGPIPE, SIG_IGN); #endif - redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); + redictAsyncContext *c = redictAsyncConnect("127.0.0.1", 6379); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); return 1; } - redisLibevAttach(EV_DEFAULT_ c); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictLibevAttach(EV_DEFAULT_ c); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); ev_loop(EV_DEFAULT_ 0); return 0; } diff --git a/examples/example-libevent-ssl.c b/examples/example-libevent-ssl.c index a142b22..b15e7e2 100644 --- a/examples/example-libevent-ssl.c +++ b/examples/example-libevent-ssl.c @@ -10,29 +10,29 @@ #include #include -#include +#include #include #include -void getCallback(redisAsyncContext *c, void *r, void *privdata) { - redisReply *reply = r; +void getCallback(redictAsyncContext *c, void *r, void *privdata) { + redictReply *reply = r; if (reply == NULL) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void connectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void connectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void disconnectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } @@ -61,36 +61,36 @@ int main (int argc, char **argv) { const char *certKey = argv[5]; const char *caCert = argc > 5 ? argv[6] : NULL; - redisSSLContext *ssl; - redisSSLContextError ssl_error = REDIS_SSL_CTX_NONE; + redictSSLContext *ssl; + redictSSLContextError ssl_error = REDICT_SSL_CTX_NONE; - redisInitOpenSSL(); + redictInitOpenSSL(); - ssl = redisCreateSSLContext(caCert, NULL, + ssl = redictCreateSSLContext(caCert, NULL, cert, certKey, NULL, &ssl_error); if (!ssl) { printf("Error: %s\n", redictSSLContextGetError(ssl_error)); return 1; } - redisAsyncContext *c = redisAsyncConnect(hostname, port); + redictAsyncContext *c = redictAsyncConnect(hostname, port); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); return 1; } - if (redisInitiateSSLWithContext(&c->c, ssl) != REDIS_OK) { + if (redictInitiateSSLWithContext(&c->c, ssl) != REDICT_OK) { printf("SSL Error!\n"); exit(1); } - redisLibeventAttach(c,base); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", value, nvalue); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictLibeventAttach(c,base); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", value, nvalue); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); event_base_dispatch(base); - redisFreeSSLContext(ssl); + redictFreeSSLContext(ssl); return 0; } diff --git a/examples/example-libevent.c b/examples/example-libevent.c index 747f343..efc21d6 100644 --- a/examples/example-libevent.c +++ b/examples/example-libevent.c @@ -13,8 +13,8 @@ #include #include -void getCallback(redisAsyncContext *c, void *r, void *privdata) { - redisReply *reply = r; +void getCallback(redictAsyncContext *c, void *r, void *privdata) { + redictReply *reply = r; if (reply == NULL) { if (c->errstr) { printf("errstr: %s\n", c->errstr); @@ -24,19 +24,19 @@ void getCallback(redisAsyncContext *c, void *r, void *privdata) { printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void connectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void connectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void disconnectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } @@ -49,25 +49,25 @@ int main (int argc, char **argv) { #endif struct event_base *base = event_base_new(); - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, "127.0.0.1", 6379); + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, "127.0.0.1", 6379); struct timeval tv = {0}; tv.tv_sec = 1; options.connect_timeout = &tv; - redisAsyncContext *c = redisAsyncConnectWithOptions(&options); + redictAsyncContext *c = redictAsyncConnectWithOptions(&options); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); return 1; } - redisLibeventAttach(c,base); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictLibeventAttach(c,base); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); event_base_dispatch(base); return 0; } diff --git a/examples/example-libhv.c b/examples/example-libhv.c index 4878039..ca053c0 100644 --- a/examples/example-libhv.c +++ b/examples/example-libhv.c @@ -13,37 +13,37 @@ #include #include -void getCallback(redisAsyncContext *c, void *r, void *privdata) { - redisReply *reply = r; +void getCallback(redictAsyncContext *c, void *r, void *privdata) { + redictReply *reply = r; if (reply == NULL) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void debugCallback(redisAsyncContext *c, void *r, void *privdata) { +void debugCallback(redictAsyncContext *c, void *r, void *privdata) { (void)privdata; - redisReply *reply = r; + redictReply *reply = r; if (reply == NULL) { printf("`DEBUG SLEEP` error: %s\n", c->errstr ? c->errstr : "unknown error"); return; } - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void connectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void connectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void disconnectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } @@ -55,7 +55,7 @@ int main (int argc, char **argv) { signal(SIGPIPE, SIG_IGN); #endif - redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); + redictAsyncContext *c = redictAsyncConnect("127.0.0.1", 6379); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); @@ -63,13 +63,13 @@ int main (int argc, char **argv) { } hloop_t* loop = hloop_new(HLOOP_FLAG_QUIT_WHEN_NO_ACTIVE_EVENTS); - redisLibhvAttach(c, loop); - redisAsyncSetTimeout(c, (struct timeval){.tv_sec = 0, .tv_usec = 500000}); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); - redisAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %d", 1); + redictLibhvAttach(c, loop); + redictAsyncSetTimeout(c, (struct timeval){.tv_sec = 0, .tv_usec = 500000}); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %d", 1); hloop_run(loop); hloop_free(&loop); return 0; diff --git a/examples/example-libsdevent.c b/examples/example-libsdevent.c index 8599b76..6e544fc 100644 --- a/examples/example-libsdevent.c +++ b/examples/example-libsdevent.c @@ -13,20 +13,20 @@ #include #include -void debugCallback(redisAsyncContext *c, void *r, void *privdata) { +void debugCallback(redictAsyncContext *c, void *r, void *privdata) { (void)privdata; - redisReply *reply = r; + redictReply *reply = r; if (reply == NULL) { /* The DEBUG SLEEP command will almost always fail, because we have set a 1 second timeout */ printf("`DEBUG SLEEP` error: %s\n", c->errstr ? c->errstr : "unknown error"); return; } /* Disconnect after receiving the reply of DEBUG SLEEP (which will not)*/ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void getCallback(redisAsyncContext *c, void *r, void *privdata) { - redisReply *reply = r; +void getCallback(redictAsyncContext *c, void *r, void *privdata) { + redictReply *reply = r; if (reply == NULL) { printf("`GET key` error: %s\n", c->errstr ? c->errstr : "unknown error"); return; @@ -34,19 +34,19 @@ void getCallback(redisAsyncContext *c, void *r, void *privdata) { printf("`GET key` result: argv[%s]: %s\n", (char*)privdata, reply->str); /* start another request that demonstrate timeout */ - redisAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %f", 1.5); + redictAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %f", 1.5); } -void connectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void connectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("connect error: %s\n", c->errstr); return; } printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void disconnectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("disconnect because of error: %s\n", c->errstr); return; } @@ -59,17 +59,17 @@ int main (int argc, char **argv) { struct sd_event *event; sd_event_default(&event); - redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); + redictAsyncContext *c = redictAsyncConnect("127.0.0.1", 6379); if (c->err) { printf("Error: %s\n", c->errstr); - redisAsyncFree(c); + redictAsyncFree(c); return 1; } - redisLibsdeventAttach(c,event); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncSetTimeout(c, (struct timeval){ .tv_sec = 1, .tv_usec = 0}); + redictLibsdeventAttach(c,event); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncSetTimeout(c, (struct timeval){ .tv_sec = 1, .tv_usec = 0}); /* In this demo, we first `set key`, then `get key` to demonstrate the basic usage of libsdevent adapter. @@ -78,8 +78,8 @@ int main (int argc, char **argv) { timeout error, which is shown in the `debugCallback`. */ - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); /* sd-event does not quit when there are no handlers registered. Manually exit after 1.5 seconds */ sd_event_source *s; diff --git a/examples/example-libuv.c b/examples/example-libuv.c index 7d0e624..c8992bc 100644 --- a/examples/example-libuv.c +++ b/examples/example-libuv.c @@ -13,20 +13,20 @@ #include #include -void debugCallback(redisAsyncContext *c, void *r, void *privdata) { +void debugCallback(redictAsyncContext *c, void *r, void *privdata) { (void)privdata; //unused - redisReply *reply = r; + redictReply *reply = r; if (reply == NULL) { /* The DEBUG SLEEP command will almost always fail, because we have set a 1 second timeout */ printf("`DEBUG SLEEP` error: %s\n", c->errstr ? c->errstr : "unknown error"); return; } /* Disconnect after receiving the reply of DEBUG SLEEP (which will not)*/ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void getCallback(redisAsyncContext *c, void *r, void *privdata) { - redisReply *reply = r; +void getCallback(redictAsyncContext *c, void *r, void *privdata) { + redictReply *reply = r; if (reply == NULL) { printf("`GET key` error: %s\n", c->errstr ? c->errstr : "unknown error"); return; @@ -34,19 +34,19 @@ void getCallback(redisAsyncContext *c, void *r, void *privdata) { printf("`GET key` result: argv[%s]: %s\n", (char*)privdata, reply->str); /* start another request that demonstrate timeout */ - redisAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %f", 1.5); + redictAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %f", 1.5); } -void connectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void connectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("connect error: %s\n", c->errstr); return; } printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void disconnectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("disconnect because of error: %s\n", c->errstr); return; } @@ -60,17 +60,17 @@ int main (int argc, char **argv) { uv_loop_t* loop = uv_default_loop(); - redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); + redictAsyncContext *c = redictAsyncConnect("127.0.0.1", 6379); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); return 1; } - redisLibuvAttach(c,loop); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncSetTimeout(c, (struct timeval){ .tv_sec = 1, .tv_usec = 0}); + redictLibuvAttach(c,loop); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncSetTimeout(c, (struct timeval){ .tv_sec = 1, .tv_usec = 0}); /* In this demo, we first `set key`, then `get key` to demonstrate the basic usage of libuv adapter. @@ -79,8 +79,8 @@ int main (int argc, char **argv) { timeout error, which is shown in the `debugCallback`. */ - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); uv_run(loop, UV_RUN_DEFAULT); return 0; diff --git a/examples/example-macosx.c b/examples/example-macosx.c index 659d3b5..265afe4 100644 --- a/examples/example-macosx.c +++ b/examples/example-macosx.c @@ -12,25 +12,25 @@ #include #include -void getCallback(redisAsyncContext *c, void *r, void *privdata) { - redisReply *reply = r; +void getCallback(redictAsyncContext *c, void *r, void *privdata) { + redictReply *reply = r; if (reply == NULL) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void connectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void connectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void disconnectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } @@ -47,20 +47,20 @@ int main (int argc, char **argv) { return 1; } - redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); + redictAsyncContext *c = redictAsyncConnect("127.0.0.1", 6379); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); return 1; } - redisMacOSAttach(c, loop); + redictMacOSAttach(c, loop); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); CFRunLoopRun(); diff --git a/examples/example-poll.c b/examples/example-poll.c index eb53659..75d4fd5 100644 --- a/examples/example-poll.c +++ b/examples/example-poll.c @@ -16,17 +16,17 @@ /* Put in the global scope, so that loop can be explicitly stopped */ static int exit_loop = 0; -void getCallback(redisAsyncContext *c, void *r, void *privdata) { - redisReply *reply = r; +void getCallback(redictAsyncContext *c, void *r, void *privdata) { + redictReply *reply = r; if (reply == NULL) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void connectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void connectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); exit_loop = 1; return; @@ -35,9 +35,9 @@ void connectCallback(const redisAsyncContext *c, int status) { printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { +void disconnectCallback(const redictAsyncContext *c, int status) { exit_loop = 1; - if (status != REDIS_OK) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } @@ -48,21 +48,21 @@ void disconnectCallback(const redisAsyncContext *c, int status) { int main (int argc, char **argv) { signal(SIGPIPE, SIG_IGN); - redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); + redictAsyncContext *c = redictAsyncConnect("127.0.0.1", 6379); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); return 1; } - redisPollAttach(c); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictPollAttach(c); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); while (!exit_loop) { - redisPollTick(c, 0.1); + redictPollTick(c, 0.1); } return 0; } diff --git a/examples/example-push.c b/examples/example-push.c index ce28c38..1d6d0b5 100644 --- a/examples/example-push.c +++ b/examples/example-push.c @@ -19,12 +19,12 @@ exit(-1); \ } while (0) -static void assertReplyAndFree(redisContext *context, redisReply *reply, int type) { +static void assertReplyAndFree(redictContext *context, redictReply *reply, int type) { if (reply == NULL) panicAbort("NULL reply from server (error: %s)", context->errstr); if (reply->type != type) { - if (reply->type == REDIS_REPLY_ERROR) + if (reply->type == REDICT_REPLY_ERROR) fprintf(stderr, "Redict Error: %s\n", reply->str); panicAbort("Expected reply type %d but got type %d", type, reply->type); @@ -34,34 +34,34 @@ static void assertReplyAndFree(redisContext *context, redisReply *reply, int typ } /* Switch to the RESP3 protocol and enable client tracking */ -static void enableClientTracking(redisContext *c) { - redisReply *reply = redisCommand(c, "HELLO 3"); +static void enableClientTracking(redictContext *c) { + redictReply *reply = redictCommand(c, "HELLO 3"); if (reply == NULL || c->err) { panicAbort("NULL reply or server error (error: %s)", c->errstr); } - if (reply->type != REDIS_REPLY_MAP) { + if (reply->type != REDICT_REPLY_MAP) { fprintf(stderr, "Error: Can't send HELLO 3 command. Are you sure you're "); fprintf(stderr, "connected to redict-server >= 6.0.0?\nRedict error: %s\n", - reply->type == REDIS_REPLY_ERROR ? reply->str : "(unknown)"); + reply->type == REDICT_REPLY_ERROR ? reply->str : "(unknown)"); exit(-1); } freeReplyObject(reply); /* Enable client tracking */ - reply = redisCommand(c, "CLIENT TRACKING ON"); - assertReplyAndFree(c, reply, REDIS_REPLY_STATUS); + reply = redictCommand(c, "CLIENT TRACKING ON"); + assertReplyAndFree(c, reply, REDICT_REPLY_STATUS); } void pushReplyHandler(void *privdata, void *r) { - redisReply *reply = r; + redictReply *reply = r; int *invalidations = privdata; /* Sanity check on the invalidation reply */ - if (reply->type != REDIS_REPLY_PUSH || reply->elements != 2 || - reply->element[1]->type != REDIS_REPLY_ARRAY || - reply->element[1]->element[0]->type != REDIS_REPLY_STRING) + if (reply->type != REDICT_REPLY_PUSH || reply->elements != 2 || + reply->element[1]->type != REDICT_REPLY_ARRAY || + reply->element[1]->element[0]->type != REDICT_REPLY_STRING) { panicAbort("%s", "Can't parse PUSH message!"); } @@ -76,7 +76,7 @@ void pushReplyHandler(void *privdata, void *r) { } /* We aren't actually freeing anything here, but it is included to show that we can - * have hiredis call our data destructor when freeing the context */ + * have hiredict call our data destructor when freeing the context */ void privdata_dtor(void *privdata) { unsigned int *icount = privdata; printf("privdata_dtor(): In context privdata dtor (invalidations: %u)\n", *icount); @@ -84,55 +84,55 @@ void privdata_dtor(void *privdata) { int main(int argc, char **argv) { unsigned int j, invalidations = 0; - redisContext *c; - redisReply *reply; + redictContext *c; + redictReply *reply; const char *hostname = (argc > 1) ? argv[1] : "127.0.0.1"; int port = (argc > 2) ? atoi(argv[2]) : 6379; - redisOptions o = {0}; - REDIS_OPTIONS_SET_TCP(&o, hostname, port); + redictOptions o = {0}; + REDICT_OPTIONS_SET_TCP(&o, hostname, port); /* Set our context privdata to the address of our invalidation counter. Each - * time our PUSH handler is called, hiredis will pass the privdata for context. + * time our PUSH handler is called, hiredict will pass the privdata for context. * * This could also be done after we create the context like so: * * c->privdata = &invalidations; * c->free_privdata = privdata_dtor; */ - REDIS_OPTIONS_SET_PRIVDATA(&o, &invalidations, privdata_dtor); + REDICT_OPTIONS_SET_PRIVDATA(&o, &invalidations, privdata_dtor); /* Set our custom PUSH message handler */ o.push_cb = pushReplyHandler; - c = redisConnectWithOptions(&o); + c = redictConnectWithOptions(&o); if (c == NULL || c->err) panicAbort("Connection error: %s", c ? c->errstr : "OOM"); /* Enable RESP3 and turn on client tracking */ enableClientTracking(c); - /* Set some keys and then read them back. Once we do that, Redis will deliver + /* Set some keys and then read them back. Once we do that, Redict will deliver * invalidation push messages whenever the key is modified */ for (j = 0; j < KEY_COUNT; j++) { - reply = redisCommand(c, "SET key:%d initial:%d", j, j); - assertReplyAndFree(c, reply, REDIS_REPLY_STATUS); + reply = redictCommand(c, "SET key:%d initial:%d", j, j); + assertReplyAndFree(c, reply, REDICT_REPLY_STATUS); - reply = redisCommand(c, "GET key:%d", j); - assertReplyAndFree(c, reply, REDIS_REPLY_STRING); + reply = redictCommand(c, "GET key:%d", j); + assertReplyAndFree(c, reply, REDICT_REPLY_STRING); } /* Trigger invalidation messages by updating keys we just read */ for (j = 0; j < KEY_COUNT; j++) { printf(" main(): SET key:%d update:%d\n", j, j); - reply = redisCommand(c, "SET key:%d update:%d", j, j); - assertReplyAndFree(c, reply, REDIS_REPLY_STATUS); + reply = redictCommand(c, "SET key:%d update:%d", j, j); + assertReplyAndFree(c, reply, REDICT_REPLY_STATUS); printf(" main(): SET REPLY OK\n"); } printf("\nTotal detected invalidations: %d, expected: %d\n", invalidations, KEY_COUNT); /* PING server */ - redisFree(c); + redictFree(c); } diff --git a/examples/example-qt.cpp b/examples/example-qt.cpp index 9ed61e8..8f6926c 100644 --- a/examples/example-qt.cpp +++ b/examples/example-qt.cpp @@ -12,9 +12,9 @@ using namespace std; #include "example-qt.h" -void getCallback(redisAsyncContext *, void * r, void * privdata) { +void getCallback(redictAsyncContext *, void * r, void * privdata) { - redisReply * reply = static_cast(r); + redictReply * reply = static_cast(r); ExampleQt * ex = static_cast(privdata); if (reply == nullptr || ex == nullptr) return; @@ -25,18 +25,18 @@ void getCallback(redisAsyncContext *, void * r, void * privdata) { void ExampleQt::run() { - m_ctx = redisAsyncConnect("localhost", 6379); + m_ctx = redictAsyncConnect("localhost", 6379); if (m_ctx->err) { cerr << "Error: " << m_ctx->errstr << endl; - redisAsyncFree(m_ctx); + redictAsyncFree(m_ctx); emit finished(); } m_adapter.setContext(m_ctx); - redisAsyncCommand(m_ctx, NULL, NULL, "SET key %s", m_value); - redisAsyncCommand(m_ctx, getCallback, this, "GET key"); + redictAsyncCommand(m_ctx, NULL, NULL, "SET key %s", m_value); + redictAsyncCommand(m_ctx, getCallback, this, "GET key"); } int main (int argc, char **argv) { diff --git a/examples/example-qt.h b/examples/example-qt.h index 31195ae..f48df17 100644 --- a/examples/example-qt.h +++ b/examples/example-qt.h @@ -4,8 +4,8 @@ // SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: LGPL-3.0-or-later -#ifndef __HIREDIS_EXAMPLE_QT_H -#define __HIREDIS_EXAMPLE_QT_H +#ifndef __HIREDICT_EXAMPLE_QT_H +#define __HIREDICT_EXAMPLE_QT_H #include @@ -28,11 +28,11 @@ class ExampleQt : public QObject { private: const char * m_value; - redisAsyncContext * m_ctx; - RedisQtAdapter m_adapter; + redictAsyncContext * m_ctx; + RedictQtAdapter m_adapter; friend - void getCallback(redisAsyncContext *, void *, void *); + void getCallback(redictAsyncContext *, void *, void *); }; -#endif /* !__HIREDIS_EXAMPLE_QT_H */ +#endif /* !__HIREDICT_EXAMPLE_QT_H */ diff --git a/examples/example-redictmoduleapi.c b/examples/example-redictmoduleapi.c index f929ffc..84dea0d 100644 --- a/examples/example-redictmoduleapi.c +++ b/examples/example-redictmoduleapi.c @@ -13,20 +13,20 @@ #include #include -void debugCallback(redisAsyncContext *c, void *r, void *privdata) { +void debugCallback(redictAsyncContext *c, void *r, void *privdata) { (void)privdata; //unused - redisReply *reply = r; + redictReply *reply = r; if (reply == NULL) { /* The DEBUG SLEEP command will almost always fail, because we have set a 1 second timeout */ printf("`DEBUG SLEEP` error: %s\n", c->errstr ? c->errstr : "unknown error"); return; } /* Disconnect after receiving the reply of DEBUG SLEEP (which will not)*/ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void getCallback(redisAsyncContext *c, void *r, void *privdata) { - redisReply *reply = r; +void getCallback(redictAsyncContext *c, void *r, void *privdata) { + redictReply *reply = r; if (reply == NULL) { if (c->errstr) { printf("errstr: %s\n", c->errstr); @@ -36,19 +36,19 @@ void getCallback(redisAsyncContext *c, void *r, void *privdata) { printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* start another request that demonstrate timeout */ - redisAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %f", 1.5); + redictAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %f", 1.5); } -void connectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void connectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void disconnectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } @@ -56,28 +56,26 @@ void disconnectCallback(const redisAsyncContext *c, int status) { } /* - * This example requires Redis 7.0 or above. - * - * 1- Compile this file as a shared library. Directory of "redismodule.h" must + * 1- Compile this file as a shared library. Directory of "redictmodule.h" must * be in the include path. - * gcc -fPIC -shared -I../../redis/src/ -I.. example-redismoduleapi.c -o example-redismoduleapi.so + * gcc -fPIC -shared -I../../redict/src/ -I.. example-redictmoduleapi.c -o example-redictmoduleapi.so * * 2- Load module: - * redis-server --loadmodule ./example-redismoduleapi.so value + * redict-server --loadmodule ./example-redictmoduleapi.so value */ -int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { +int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) { - int ret = RedisModule_Init(ctx, "example-redictmoduleapi", 1, REDISMODULE_APIVER_1); - if (ret != REDISMODULE_OK) { + int ret = RedictModule_Init(ctx, "example-redictmoduleapi", 1, REDICTMODULE_APIVER_1); + if (ret != REDICTMODULE_OK) { printf("error module init \n"); - return REDISMODULE_ERR; + return REDICTMODULE_ERR; } - if (redisModuleCompatibilityCheck() != REDIS_OK) { - return REDISMODULE_ERR; + if (redictModuleCompatibilityCheck() != REDICT_OK) { + return REDICTMODULE_ERR; } - redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); + redictAsyncContext *c = redictAsyncConnect("127.0.0.1", 6379); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); @@ -85,13 +83,13 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) } size_t len; - const char *val = RedisModule_StringPtrLen(argv[argc-1], &len); + const char *val = RedictModule_StringPtrLen(argv[argc-1], &len); - RedisModuleCtx *module_ctx = RedisModule_GetDetachedThreadSafeContext(ctx); - redisModuleAttach(c, module_ctx); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncSetTimeout(c, (struct timeval){ .tv_sec = 1, .tv_usec = 0}); + RedictModuleCtx *module_ctx = RedictModule_GetDetachedThreadSafeContext(ctx); + redictModuleAttach(c, module_ctx); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncSetTimeout(c, (struct timeval){ .tv_sec = 1, .tv_usec = 0}); /* In this demo, we first `set key`, then `get key` to demonstrate the basic usage of the adapter. @@ -100,7 +98,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) timeout error, which is shown in the `debugCallback`. */ - redisAsyncCommand(c, NULL, NULL, "SET key %b", val, len); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictAsyncCommand(c, NULL, NULL, "SET key %b", val, len); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); return 0; } diff --git a/examples/example-ssl.c b/examples/example-ssl.c index ac3dfb8..c9b8818 100644 --- a/examples/example-ssl.c +++ b/examples/example-ssl.c @@ -9,7 +9,7 @@ #include #include -#include +#include #ifdef _MSC_VER #include /* For struct timeval */ @@ -17,10 +17,10 @@ int main(int argc, char **argv) { unsigned int j; - redisSSLContext *ssl; - redisSSLContextError ssl_error = REDIS_SSL_CTX_NONE; - redisContext *c; - redisReply *reply; + redictSSLContext *ssl; + redictSSLContextError ssl_error = REDICT_SSL_CTX_NONE; + redictContext *c; + redictReply *reply; if (argc < 4) { printf("Usage: %s [ca]\n", argv[0]); exit(1); @@ -31,78 +31,78 @@ int main(int argc, char **argv) { const char *key = argv[4]; const char *ca = argc > 4 ? argv[5] : NULL; - redisInitOpenSSL(); - ssl = redisCreateSSLContext(ca, NULL, cert, key, NULL, &ssl_error); - if (!ssl || ssl_error != REDIS_SSL_CTX_NONE) { + redictInitOpenSSL(); + ssl = redictCreateSSLContext(ca, NULL, cert, key, NULL, &ssl_error); + if (!ssl || ssl_error != REDICT_SSL_CTX_NONE) { printf("SSL Context error: %s\n", redictSSLContextGetError(ssl_error)); exit(1); } struct timeval tv = { 1, 500000 }; // 1.5 seconds - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, hostname, port); + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, hostname, port); options.connect_timeout = &tv; - c = redisConnectWithOptions(&options); + c = redictConnectWithOptions(&options); if (c == NULL || c->err) { if (c) { printf("Connection error: %s\n", c->errstr); - redisFree(c); + redictFree(c); } else { printf("Connection error: can't allocate redict context\n"); } exit(1); } - if (redisInitiateSSLWithContext(c, ssl) != REDIS_OK) { + if (redictInitiateSSLWithContext(c, ssl) != REDICT_OK) { printf("Couldn't initialize SSL!\n"); printf("Error: %s\n", c->errstr); - redisFree(c); + redictFree(c); exit(1); } /* PING server */ - reply = redisCommand(c,"PING"); + reply = redictCommand(c,"PING"); printf("PING: %s\n", reply->str); freeReplyObject(reply); /* Set a key */ - reply = redisCommand(c,"SET %s %s", "foo", "hello world"); + reply = redictCommand(c,"SET %s %s", "foo", "hello world"); printf("SET: %s\n", reply->str); freeReplyObject(reply); /* Set a key using binary safe API */ - reply = redisCommand(c,"SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5); + reply = redictCommand(c,"SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5); printf("SET (binary API): %s\n", reply->str); freeReplyObject(reply); /* Try a GET and two INCR */ - reply = redisCommand(c,"GET foo"); + reply = redictCommand(c,"GET foo"); printf("GET foo: %s\n", reply->str); freeReplyObject(reply); - reply = redisCommand(c,"INCR counter"); + reply = redictCommand(c,"INCR counter"); printf("INCR counter: %lld\n", reply->integer); freeReplyObject(reply); /* again ... */ - reply = redisCommand(c,"INCR counter"); + reply = redictCommand(c,"INCR counter"); printf("INCR counter: %lld\n", reply->integer); freeReplyObject(reply); /* Create a list of numbers, from 0 to 9 */ - reply = redisCommand(c,"DEL mylist"); + reply = redictCommand(c,"DEL mylist"); freeReplyObject(reply); for (j = 0; j < 10; j++) { char buf[64]; snprintf(buf,64,"%u",j); - reply = redisCommand(c,"LPUSH mylist element-%s", buf); + reply = redictCommand(c,"LPUSH mylist element-%s", buf); freeReplyObject(reply); } /* Let's check what we have inside the list */ - reply = redisCommand(c,"LRANGE mylist 0 -1"); - if (reply->type == REDIS_REPLY_ARRAY) { + reply = redictCommand(c,"LRANGE mylist 0 -1"); + if (reply->type == REDICT_REPLY_ARRAY) { for (j = 0; j < reply->elements; j++) { printf("%u) %s\n", j, reply->element[j]->str); } @@ -110,9 +110,9 @@ int main(int argc, char **argv) { freeReplyObject(reply); /* Disconnects and frees the context */ - redisFree(c); + redictFree(c); - redisFreeSSLContext(ssl); + redictFreeSSLContext(ssl); return 0; } diff --git a/examples/example.c b/examples/example.c index 41c8189..28e77e4 100644 --- a/examples/example.c +++ b/examples/example.c @@ -13,10 +13,10 @@ #include /* For struct timeval */ #endif -static void example_argv_command(redisContext *c, size_t n) { +static void example_argv_command(redictContext *c, size_t n) { char **argv, tmp[42]; size_t *argvlen; - redisReply *reply; + redictReply *reply; /* We're allocating two additional elements for command and key */ argv = malloc(sizeof(*argv) * (2 + n)); @@ -36,17 +36,17 @@ static void example_argv_command(redisContext *c, size_t n) { argv[i] = strdup(tmp); } - /* Execute the command using redisCommandArgv. We're sending the arguments with + /* Execute the command using redictCommandArgv. We're sending the arguments with * two explicit arrays. One for each argument's string, and the other for its * length. */ - reply = redisCommandArgv(c, n + 2, (const char **)argv, (const size_t*)argvlen); + reply = redictCommandArgv(c, n + 2, (const char **)argv, (const size_t*)argvlen); if (reply == NULL || c->err) { fprintf(stderr, "Error: Couldn't execute redictCommandArgv\n"); exit(1); } - if (reply->type == REDIS_REPLY_INTEGER) { + if (reply->type == REDICT_REPLY_INTEGER) { printf("%s reply: %lld\n", argv[0], reply->integer); } @@ -63,8 +63,8 @@ static void example_argv_command(redisContext *c, size_t n) { int main(int argc, char **argv) { unsigned int j, isunix = 0; - redisContext *c; - redisReply *reply; + redictContext *c; + redictReply *reply; const char *hostname = (argc > 1) ? argv[1] : "127.0.0.1"; if (argc > 2) { @@ -79,14 +79,14 @@ int main(int argc, char **argv) { struct timeval timeout = { 1, 500000 }; // 1.5 seconds if (isunix) { - c = redisConnectUnixWithTimeout(hostname, timeout); + c = redictConnectUnixWithTimeout(hostname, timeout); } else { - c = redisConnectWithTimeout(hostname, port, timeout); + c = redictConnectWithTimeout(hostname, port, timeout); } if (c == NULL || c->err) { if (c) { printf("Connection error: %s\n", c->errstr); - redisFree(c); + redictFree(c); } else { printf("Connection error: can't allocate redict context\n"); } @@ -94,58 +94,58 @@ int main(int argc, char **argv) { } /* PING server */ - reply = redisCommand(c,"PING"); + reply = redictCommand(c,"PING"); printf("PING: %s\n", reply->str); freeReplyObject(reply); /* Set a key */ - reply = redisCommand(c,"SET %s %s", "foo", "hello world"); + reply = redictCommand(c,"SET %s %s", "foo", "hello world"); printf("SET: %s\n", reply->str); freeReplyObject(reply); /* Set a key using binary safe API */ - reply = redisCommand(c,"SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5); + reply = redictCommand(c,"SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5); printf("SET (binary API): %s\n", reply->str); freeReplyObject(reply); /* Try a GET and two INCR */ - reply = redisCommand(c,"GET foo"); + reply = redictCommand(c,"GET foo"); printf("GET foo: %s\n", reply->str); freeReplyObject(reply); - reply = redisCommand(c,"INCR counter"); + reply = redictCommand(c,"INCR counter"); printf("INCR counter: %lld\n", reply->integer); freeReplyObject(reply); /* again ... */ - reply = redisCommand(c,"INCR counter"); + reply = redictCommand(c,"INCR counter"); printf("INCR counter: %lld\n", reply->integer); freeReplyObject(reply); /* Create a list of numbers, from 0 to 9 */ - reply = redisCommand(c,"DEL mylist"); + reply = redictCommand(c,"DEL mylist"); freeReplyObject(reply); for (j = 0; j < 10; j++) { char buf[64]; snprintf(buf,64,"%u",j); - reply = redisCommand(c,"LPUSH mylist element-%s", buf); + reply = redictCommand(c,"LPUSH mylist element-%s", buf); freeReplyObject(reply); } /* Let's check what we have inside the list */ - reply = redisCommand(c,"LRANGE mylist 0 -1"); - if (reply->type == REDIS_REPLY_ARRAY) { + reply = redictCommand(c,"LRANGE mylist 0 -1"); + if (reply->type == REDICT_REPLY_ARRAY) { for (j = 0; j < reply->elements; j++) { printf("%u) %s\n", j, reply->element[j]->str); } } freeReplyObject(reply); - /* See function for an example of redisCommandArgv */ + /* See function for an example of redictCommandArgv */ example_argv_command(c, 10); /* Disconnects and frees the context */ - redisFree(c); + redictFree(c); return 0; } diff --git a/fmacros.h b/fmacros.h index 6f9110f..4140543 100644 --- a/fmacros.h +++ b/fmacros.h @@ -9,8 +9,8 @@ * */ -#ifndef __HIREDIS_FMACRO_H -#define __HIREDIS_FMACRO_H +#ifndef __HIREDICT_FMACRO_H +#define __HIREDICT_FMACRO_H #ifndef _AIX #define _XOPEN_SOURCE 600 diff --git a/fuzzing/format_command_fuzzer.c b/fuzzing/format_command_fuzzer.c index 99fde7b..cbca8b0 100644 --- a/fuzzing/format_command_fuzzer.c +++ b/fuzzing/format_command_fuzzer.c @@ -32,7 +32,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { memcpy(new_str, data, size); new_str[size] = '\0'; - if (redisFormatCommand(&cmd, new_str) != -1) + if (redictFormatCommand(&cmd, new_str) != -1) hi_free(cmd); free(new_str); diff --git a/hiredict-config.cmake.in b/hiredict-config.cmake.in index 0339858..ff170b1 100644 --- a/hiredict-config.cmake.in +++ b/hiredict-config.cmake.in @@ -1,13 +1,13 @@ @PACKAGE_INIT@ -set_and_check(hiredis_INCLUDEDIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(hiredict_INCLUDEDIR "@PACKAGE_INCLUDE_INSTALL_DIR@") -IF (NOT TARGET hiredis::@hiredis_export_name@) - INCLUDE(${CMAKE_CURRENT_LIST_DIR}/hiredis-targets.cmake) +IF (NOT TARGET hiredict::@hiredict_export_name@) + INCLUDE(${CMAKE_CURRENT_LIST_DIR}/hiredict-targets.cmake) ENDIF() -SET(hiredis_LIBRARIES hiredis::@hiredis_export_name@) -SET(hiredis_INCLUDE_DIRS ${hiredis_INCLUDEDIR}) +SET(hiredict_LIBRARIES hiredict::@hiredict_export_name@) +SET(hiredict_INCLUDE_DIRS ${hiredict_INCLUDEDIR}) -check_required_components(hiredis) +check_required_components(hiredict) diff --git a/hiredict.c b/hiredict.c index 1686abf..080e38d 100644 --- a/hiredict.c +++ b/hiredict.c @@ -28,29 +28,29 @@ #include "async.h" #include "win32.h" -extern int redisContextUpdateConnectTimeout(redisContext *c, const struct timeval *timeout); -extern int redisContextUpdateCommandTimeout(redisContext *c, const struct timeval *timeout); +extern int redictContextUpdateConnectTimeout(redictContext *c, const struct timeval *timeout); +extern int redictContextUpdateCommandTimeout(redictContext *c, const struct timeval *timeout); -static redisContextFuncs redisContextDefaultFuncs = { - .close = redisNetClose, +static redictContextFuncs redictContextDefaultFuncs = { + .close = redictNetClose, .free_privctx = NULL, - .async_read = redisAsyncRead, - .async_write = redisAsyncWrite, - .read = redisNetRead, - .write = redisNetWrite + .async_read = redictAsyncRead, + .async_write = redictAsyncWrite, + .read = redictNetRead, + .write = redictNetWrite }; -static redisReply *createReplyObject(int type); -static void *createStringObject(const redisReadTask *task, char *str, size_t len); -static void *createArrayObject(const redisReadTask *task, size_t elements); -static void *createIntegerObject(const redisReadTask *task, long long value); -static void *createDoubleObject(const redisReadTask *task, double value, char *str, size_t len); -static void *createNilObject(const redisReadTask *task); -static void *createBoolObject(const redisReadTask *task, int bval); +static redictReply *createReplyObject(int type); +static void *createStringObject(const redictReadTask *task, char *str, size_t len); +static void *createArrayObject(const redictReadTask *task, size_t elements); +static void *createIntegerObject(const redictReadTask *task, long long value); +static void *createDoubleObject(const redictReadTask *task, double value, char *str, size_t len); +static void *createNilObject(const redictReadTask *task); +static void *createBoolObject(const redictReadTask *task, int bval); /* Default set of functions to build the reply. Keep in mind that such a * function returning NULL is interpreted as OOM. */ -static redisReplyObjectFunctions defaultFunctions = { +static redictReplyObjectFunctions defaultFunctions = { createStringObject, createArrayObject, createIntegerObject, @@ -61,8 +61,8 @@ static redisReplyObjectFunctions defaultFunctions = { }; /* Create a reply object */ -static redisReply *createReplyObject(int type) { - redisReply *r = hi_calloc(1,sizeof(*r)); +static redictReply *createReplyObject(int type) { + redictReply *r = hi_calloc(1,sizeof(*r)); if (r == NULL) return NULL; @@ -73,56 +73,56 @@ static redisReply *createReplyObject(int type) { /* Free a reply object */ void freeReplyObject(void *reply) { - redisReply *r = reply; + redictReply *r = reply; size_t j; if (r == NULL) return; switch(r->type) { - case REDIS_REPLY_INTEGER: - case REDIS_REPLY_NIL: - case REDIS_REPLY_BOOL: + case REDICT_REPLY_INTEGER: + case REDICT_REPLY_NIL: + case REDICT_REPLY_BOOL: break; /* Nothing to free */ - case REDIS_REPLY_ARRAY: - case REDIS_REPLY_MAP: - case REDIS_REPLY_ATTR: - case REDIS_REPLY_SET: - case REDIS_REPLY_PUSH: + case REDICT_REPLY_ARRAY: + case REDICT_REPLY_MAP: + case REDICT_REPLY_ATTR: + case REDICT_REPLY_SET: + case REDICT_REPLY_PUSH: if (r->element != NULL) { for (j = 0; j < r->elements; j++) freeReplyObject(r->element[j]); hi_free(r->element); } break; - case REDIS_REPLY_ERROR: - case REDIS_REPLY_STATUS: - case REDIS_REPLY_STRING: - case REDIS_REPLY_DOUBLE: - case REDIS_REPLY_VERB: - case REDIS_REPLY_BIGNUM: + case REDICT_REPLY_ERROR: + case REDICT_REPLY_STATUS: + case REDICT_REPLY_STRING: + case REDICT_REPLY_DOUBLE: + case REDICT_REPLY_VERB: + case REDICT_REPLY_BIGNUM: hi_free(r->str); break; } hi_free(r); } -static void *createStringObject(const redisReadTask *task, char *str, size_t len) { - redisReply *r, *parent; +static void *createStringObject(const redictReadTask *task, char *str, size_t len) { + redictReply *r, *parent; char *buf; r = createReplyObject(task->type); if (r == NULL) return NULL; - assert(task->type == REDIS_REPLY_ERROR || - task->type == REDIS_REPLY_STATUS || - task->type == REDIS_REPLY_STRING || - task->type == REDIS_REPLY_VERB || - task->type == REDIS_REPLY_BIGNUM); + assert(task->type == REDICT_REPLY_ERROR || + task->type == REDICT_REPLY_STATUS || + task->type == REDICT_REPLY_STRING || + task->type == REDICT_REPLY_VERB || + task->type == REDICT_REPLY_BIGNUM); /* Copy string value */ - if (task->type == REDIS_REPLY_VERB) { + if (task->type == REDICT_REPLY_VERB) { buf = hi_malloc(len-4+1); /* Skip 4 bytes of verbatim type header. */ if (buf == NULL) goto oom; @@ -143,11 +143,11 @@ static void *createStringObject(const redisReadTask *task, char *str, size_t len if (task->parent) { parent = task->parent->obj; - assert(parent->type == REDIS_REPLY_ARRAY || - parent->type == REDIS_REPLY_MAP || - parent->type == REDIS_REPLY_ATTR || - parent->type == REDIS_REPLY_SET || - parent->type == REDIS_REPLY_PUSH); + assert(parent->type == REDICT_REPLY_ARRAY || + parent->type == REDICT_REPLY_MAP || + parent->type == REDICT_REPLY_ATTR || + parent->type == REDICT_REPLY_SET || + parent->type == REDICT_REPLY_PUSH); parent->element[task->idx] = r; } return r; @@ -157,15 +157,15 @@ oom: return NULL; } -static void *createArrayObject(const redisReadTask *task, size_t elements) { - redisReply *r, *parent; +static void *createArrayObject(const redictReadTask *task, size_t elements) { + redictReply *r, *parent; r = createReplyObject(task->type); if (r == NULL) return NULL; if (elements > 0) { - r->element = hi_calloc(elements,sizeof(redisReply*)); + r->element = hi_calloc(elements,sizeof(redictReply*)); if (r->element == NULL) { freeReplyObject(r); return NULL; @@ -176,20 +176,20 @@ static void *createArrayObject(const redisReadTask *task, size_t elements) { if (task->parent) { parent = task->parent->obj; - assert(parent->type == REDIS_REPLY_ARRAY || - parent->type == REDIS_REPLY_MAP || - parent->type == REDIS_REPLY_ATTR || - parent->type == REDIS_REPLY_SET || - parent->type == REDIS_REPLY_PUSH); + assert(parent->type == REDICT_REPLY_ARRAY || + parent->type == REDICT_REPLY_MAP || + parent->type == REDICT_REPLY_ATTR || + parent->type == REDICT_REPLY_SET || + parent->type == REDICT_REPLY_PUSH); parent->element[task->idx] = r; } return r; } -static void *createIntegerObject(const redisReadTask *task, long long value) { - redisReply *r, *parent; +static void *createIntegerObject(const redictReadTask *task, long long value) { + redictReply *r, *parent; - r = createReplyObject(REDIS_REPLY_INTEGER); + r = createReplyObject(REDICT_REPLY_INTEGER); if (r == NULL) return NULL; @@ -197,23 +197,23 @@ static void *createIntegerObject(const redisReadTask *task, long long value) { if (task->parent) { parent = task->parent->obj; - assert(parent->type == REDIS_REPLY_ARRAY || - parent->type == REDIS_REPLY_MAP || - parent->type == REDIS_REPLY_ATTR || - parent->type == REDIS_REPLY_SET || - parent->type == REDIS_REPLY_PUSH); + assert(parent->type == REDICT_REPLY_ARRAY || + parent->type == REDICT_REPLY_MAP || + parent->type == REDICT_REPLY_ATTR || + parent->type == REDICT_REPLY_SET || + parent->type == REDICT_REPLY_PUSH); parent->element[task->idx] = r; } return r; } -static void *createDoubleObject(const redisReadTask *task, double value, char *str, size_t len) { - redisReply *r, *parent; +static void *createDoubleObject(const redictReadTask *task, double value, char *str, size_t len) { + redictReply *r, *parent; if (len == SIZE_MAX) // Prevents hi_malloc(0) if len equals to SIZE_MAX return NULL; - r = createReplyObject(REDIS_REPLY_DOUBLE); + r = createReplyObject(REDICT_REPLY_DOUBLE); if (r == NULL) return NULL; @@ -226,7 +226,7 @@ static void *createDoubleObject(const redisReadTask *task, double value, char *s /* The double reply also has the original protocol string representing a * double as a null terminated string. This way the caller does not need - * to format back for string conversion, especially since Redis does efforts + * to format back for string conversion, especially since Redict does efforts * to make the string more human readable avoiding the calssical double * decimal string conversion artifacts. */ memcpy(r->str, str, len); @@ -235,39 +235,39 @@ static void *createDoubleObject(const redisReadTask *task, double value, char *s if (task->parent) { parent = task->parent->obj; - assert(parent->type == REDIS_REPLY_ARRAY || - parent->type == REDIS_REPLY_MAP || - parent->type == REDIS_REPLY_ATTR || - parent->type == REDIS_REPLY_SET || - parent->type == REDIS_REPLY_PUSH); + assert(parent->type == REDICT_REPLY_ARRAY || + parent->type == REDICT_REPLY_MAP || + parent->type == REDICT_REPLY_ATTR || + parent->type == REDICT_REPLY_SET || + parent->type == REDICT_REPLY_PUSH); parent->element[task->idx] = r; } return r; } -static void *createNilObject(const redisReadTask *task) { - redisReply *r, *parent; +static void *createNilObject(const redictReadTask *task) { + redictReply *r, *parent; - r = createReplyObject(REDIS_REPLY_NIL); + r = createReplyObject(REDICT_REPLY_NIL); if (r == NULL) return NULL; if (task->parent) { parent = task->parent->obj; - assert(parent->type == REDIS_REPLY_ARRAY || - parent->type == REDIS_REPLY_MAP || - parent->type == REDIS_REPLY_ATTR || - parent->type == REDIS_REPLY_SET || - parent->type == REDIS_REPLY_PUSH); + assert(parent->type == REDICT_REPLY_ARRAY || + parent->type == REDICT_REPLY_MAP || + parent->type == REDICT_REPLY_ATTR || + parent->type == REDICT_REPLY_SET || + parent->type == REDICT_REPLY_PUSH); parent->element[task->idx] = r; } return r; } -static void *createBoolObject(const redisReadTask *task, int bval) { - redisReply *r, *parent; +static void *createBoolObject(const redictReadTask *task, int bval) { + redictReply *r, *parent; - r = createReplyObject(REDIS_REPLY_BOOL); + r = createReplyObject(REDICT_REPLY_BOOL); if (r == NULL) return NULL; @@ -275,18 +275,18 @@ static void *createBoolObject(const redisReadTask *task, int bval) { if (task->parent) { parent = task->parent->obj; - assert(parent->type == REDIS_REPLY_ARRAY || - parent->type == REDIS_REPLY_MAP || - parent->type == REDIS_REPLY_ATTR || - parent->type == REDIS_REPLY_SET || - parent->type == REDIS_REPLY_PUSH); + assert(parent->type == REDICT_REPLY_ARRAY || + parent->type == REDICT_REPLY_MAP || + parent->type == REDICT_REPLY_ATTR || + parent->type == REDICT_REPLY_SET || + parent->type == REDICT_REPLY_PUSH); parent->element[task->idx] = r; } return r; } /* Return the number of digits of 'v' when converted to string in radix 10. - * Implementation borrowed from link in redis/src/util.c:string2ll(). */ + * Implementation borrowed from link in redict/src/util.c:string2ll(). */ static uint32_t countDigits(uint64_t v) { uint32_t result = 1; for (;;) { @@ -304,7 +304,7 @@ static size_t bulklen(size_t len) { return 1+countDigits(len)+2+len+2; } -int redisvFormatCommand(char **target, const char *format, va_list ap) { +int redictvFormatCommand(char **target, const char *format, va_list ap) { const char *c = format; char *cmd = NULL; /* final command */ int pos; /* position in final command */ @@ -541,7 +541,7 @@ cleanup: return error_type; } -/* Format a command according to the Redis protocol. This function +/* Format a command according to the Redict protocol. This function * takes a format similar to printf: * * %s represents a C null terminated string you want to interpolate @@ -550,14 +550,14 @@ cleanup: * When using %b you need to provide both the pointer to the string * and the length in bytes as a size_t. Examples: * - * len = redisFormatCommand(target, "GET %s", mykey); - * len = redisFormatCommand(target, "SET %s %b", mykey, myval, myvallen); + * len = redictFormatCommand(target, "GET %s", mykey); + * len = redictFormatCommand(target, "SET %s %b", mykey, myval, myvallen); */ -int redisFormatCommand(char **target, const char *format, ...) { +int redictFormatCommand(char **target, const char *format, ...) { va_list ap; int len; va_start(ap,format); - len = redisvFormatCommand(target,format,ap); + len = redictvFormatCommand(target,format,ap); va_end(ap); /* The API says "-1" means bad result, but we now also return "-2" in some @@ -568,13 +568,13 @@ int redisFormatCommand(char **target, const char *format, ...) { return len; } -/* Format a command according to the Redis protocol using an sds string and +/* Format a command according to the Redict protocol using an sds string and * sdscatfmt for the processing of arguments. This function takes the * number of arguments, an array with arguments and an array with their * lengths. If the latter is set to NULL, strlen will be used to compute the * argument lengths. */ -long long redisFormatSdsCommandArgv(sds *target, int argc, const char **argv, +long long redictFormatSdsCommandArgv(sds *target, int argc, const char **argv, const size_t *argvlen) { sds cmd, aux; @@ -621,16 +621,16 @@ long long redisFormatSdsCommandArgv(sds *target, int argc, const char **argv, return totlen; } -void redisFreeSdsCommand(sds cmd) { +void redictFreeSdsCommand(sds cmd) { sdsfree(cmd); } -/* Format a command according to the Redis protocol. This function takes the +/* Format a command according to the Redict protocol. This function takes the * number of arguments, an array with arguments and an array with their * lengths. If the latter is set to NULL, strlen will be used to compute the * argument lengths. */ -long long redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen) { +long long redictFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen) { char *cmd = NULL; /* final command */ size_t pos; /* position in final command */ size_t len, totlen; @@ -668,11 +668,11 @@ long long redisFormatCommandArgv(char **target, int argc, const char **argv, con return totlen; } -void redisFreeCommand(char *cmd) { +void redictFreeCommand(char *cmd) { hi_free(cmd); } -void __redisSetError(redisContext *c, int type, const char *str) { +void __redictSetError(redictContext *c, int type, const char *str) { size_t len; c->err = type; @@ -682,43 +682,43 @@ void __redisSetError(redisContext *c, int type, const char *str) { memcpy(c->errstr,str,len); c->errstr[len] = '\0'; } else { - /* Only REDIS_ERR_IO may lack a description! */ - assert(type == REDIS_ERR_IO); + /* Only REDICT_ERR_IO may lack a description! */ + assert(type == REDICT_ERR_IO); strerror_r(errno, c->errstr, sizeof(c->errstr)); } } -redisReader *redisReaderCreate(void) { - return redisReaderCreateWithFunctions(&defaultFunctions); +redictReader *redictReaderCreate(void) { + return redictReaderCreateWithFunctions(&defaultFunctions); } -static void redisPushAutoFree(void *privdata, void *reply) { +static void redictPushAutoFree(void *privdata, void *reply) { (void)privdata; freeReplyObject(reply); } -static redisContext *redisContextInit(void) { - redisContext *c; +static redictContext *redictContextInit(void) { + redictContext *c; c = hi_calloc(1, sizeof(*c)); if (c == NULL) return NULL; - c->funcs = &redisContextDefaultFuncs; + c->funcs = &redictContextDefaultFuncs; c->obuf = sdsempty(); - c->reader = redisReaderCreate(); - c->fd = REDIS_INVALID_FD; + c->reader = redictReaderCreate(); + c->fd = REDICT_INVALID_FD; if (c->obuf == NULL || c->reader == NULL) { - redisFree(c); + redictFree(c); return NULL; } return c; } -void redisFree(redisContext *c) { +void redictFree(redictContext *c) { if (c == NULL) return; @@ -727,7 +727,7 @@ void redisFree(redisContext *c) { } sdsfree(c->obuf); - redisReaderFree(c->reader); + redictReaderFree(c->reader); hi_free(c->tcp.host); hi_free(c->tcp.source_addr); hi_free(c->unix_sock.path); @@ -745,14 +745,14 @@ void redisFree(redisContext *c) { hi_free(c); } -redisFD redisFreeKeepFd(redisContext *c) { - redisFD fd = c->fd; - c->fd = REDIS_INVALID_FD; - redisFree(c); +redictFD redictFreeKeepFd(redictContext *c) { + redictFD fd = c->fd; + c->fd = REDICT_INVALID_FD; + redictFree(c); return fd; } -int redisReconnect(redisContext *c) { +int redictReconnect(redictContext *c) { c->err = 0; memset(c->errstr, '\0', strlen(c->errstr)); @@ -766,192 +766,192 @@ int redisReconnect(redisContext *c) { } sdsfree(c->obuf); - redisReaderFree(c->reader); + redictReaderFree(c->reader); c->obuf = sdsempty(); - c->reader = redisReaderCreate(); + c->reader = redictReaderCreate(); if (c->obuf == NULL || c->reader == NULL) { - __redisSetError(c, REDIS_ERR_OOM, "Out of memory"); - return REDIS_ERR; + __redictSetError(c, REDICT_ERR_OOM, "Out of memory"); + return REDICT_ERR; } - int ret = REDIS_ERR; - if (c->connection_type == REDIS_CONN_TCP) { - ret = redisContextConnectBindTcp(c, c->tcp.host, c->tcp.port, + int ret = REDICT_ERR; + if (c->connection_type == REDICT_CONN_TCP) { + ret = redictContextConnectBindTcp(c, c->tcp.host, c->tcp.port, c->connect_timeout, c->tcp.source_addr); - } else if (c->connection_type == REDIS_CONN_UNIX) { - ret = redisContextConnectUnix(c, c->unix_sock.path, c->connect_timeout); + } else if (c->connection_type == REDICT_CONN_UNIX) { + ret = redictContextConnectUnix(c, c->unix_sock.path, c->connect_timeout); } else { /* Something bad happened here and shouldn't have. There isn't enough information in the context to reconnect. */ - __redisSetError(c,REDIS_ERR_OTHER,"Not enough information to reconnect"); - ret = REDIS_ERR; + __redictSetError(c,REDICT_ERR_OTHER,"Not enough information to reconnect"); + ret = REDICT_ERR; } - if (c->command_timeout != NULL && (c->flags & REDIS_BLOCK) && c->fd != REDIS_INVALID_FD) { - redisContextSetTimeout(c, *c->command_timeout); + if (c->command_timeout != NULL && (c->flags & REDICT_BLOCK) && c->fd != REDICT_INVALID_FD) { + redictContextSetTimeout(c, *c->command_timeout); } return ret; } -redisContext *redisConnectWithOptions(const redisOptions *options) { - redisContext *c = redisContextInit(); +redictContext *redictConnectWithOptions(const redictOptions *options) { + redictContext *c = redictContextInit(); if (c == NULL) { return NULL; } - if (!(options->options & REDIS_OPT_NONBLOCK)) { - c->flags |= REDIS_BLOCK; + if (!(options->options & REDICT_OPT_NONBLOCK)) { + c->flags |= REDICT_BLOCK; } - if (options->options & REDIS_OPT_REUSEADDR) { - c->flags |= REDIS_REUSEADDR; + if (options->options & REDICT_OPT_REUSEADDR) { + c->flags |= REDICT_REUSEADDR; } - if (options->options & REDIS_OPT_NOAUTOFREE) { - c->flags |= REDIS_NO_AUTO_FREE; + if (options->options & REDICT_OPT_NOAUTOFREE) { + c->flags |= REDICT_NO_AUTO_FREE; } - if (options->options & REDIS_OPT_NOAUTOFREEREPLIES) { - c->flags |= REDIS_NO_AUTO_FREE_REPLIES; + if (options->options & REDICT_OPT_NOAUTOFREEREPLIES) { + c->flags |= REDICT_NO_AUTO_FREE_REPLIES; } - if (options->options & REDIS_OPT_PREFER_IPV4) { - c->flags |= REDIS_PREFER_IPV4; + if (options->options & REDICT_OPT_PREFER_IPV4) { + c->flags |= REDICT_PREFER_IPV4; } - if (options->options & REDIS_OPT_PREFER_IPV6) { - c->flags |= REDIS_PREFER_IPV6; + if (options->options & REDICT_OPT_PREFER_IPV6) { + c->flags |= REDICT_PREFER_IPV6; } /* Set any user supplied RESP3 PUSH handler or use freeReplyObject * as a default unless specifically flagged that we don't want one. */ if (options->push_cb != NULL) - redisSetPushCallback(c, options->push_cb); - else if (!(options->options & REDIS_OPT_NO_PUSH_AUTOFREE)) - redisSetPushCallback(c, redisPushAutoFree); + redictSetPushCallback(c, options->push_cb); + else if (!(options->options & REDICT_OPT_NO_PUSH_AUTOFREE)) + redictSetPushCallback(c, redictPushAutoFree); c->privdata = options->privdata; c->free_privdata = options->free_privdata; - if (redisContextUpdateConnectTimeout(c, options->connect_timeout) != REDIS_OK || - redisContextUpdateCommandTimeout(c, options->command_timeout) != REDIS_OK) { - __redisSetError(c, REDIS_ERR_OOM, "Out of memory"); + if (redictContextUpdateConnectTimeout(c, options->connect_timeout) != REDICT_OK || + redictContextUpdateCommandTimeout(c, options->command_timeout) != REDICT_OK) { + __redictSetError(c, REDICT_ERR_OOM, "Out of memory"); return c; } - if (options->type == REDIS_CONN_TCP) { - redisContextConnectBindTcp(c, options->endpoint.tcp.ip, + if (options->type == REDICT_CONN_TCP) { + redictContextConnectBindTcp(c, options->endpoint.tcp.ip, options->endpoint.tcp.port, options->connect_timeout, options->endpoint.tcp.source_addr); - } else if (options->type == REDIS_CONN_UNIX) { - redisContextConnectUnix(c, options->endpoint.unix_socket, + } else if (options->type == REDICT_CONN_UNIX) { + redictContextConnectUnix(c, options->endpoint.unix_socket, options->connect_timeout); - } else if (options->type == REDIS_CONN_USERFD) { + } else if (options->type == REDICT_CONN_USERFD) { c->fd = options->endpoint.fd; - c->flags |= REDIS_CONNECTED; + c->flags |= REDICT_CONNECTED; } else { - redisFree(c); + redictFree(c); return NULL; } - if (c->err == 0 && c->fd != REDIS_INVALID_FD && - options->command_timeout != NULL && (c->flags & REDIS_BLOCK)) + if (c->err == 0 && c->fd != REDICT_INVALID_FD && + options->command_timeout != NULL && (c->flags & REDICT_BLOCK)) { - redisContextSetTimeout(c, *options->command_timeout); + redictContextSetTimeout(c, *options->command_timeout); } return c; } -/* Connect to a Redis instance. On error the field error in the returned +/* Connect to a Redict instance. On error the field error in the returned * context will be set to the return value of the error function. * When no set of reply functions is given, the default set will be used. */ -redisContext *redisConnect(const char *ip, int port) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, ip, port); - return redisConnectWithOptions(&options); +redictContext *redictConnect(const char *ip, int port) { + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, ip, port); + return redictConnectWithOptions(&options); } -redisContext *redisConnectWithTimeout(const char *ip, int port, const struct timeval tv) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, ip, port); +redictContext *redictConnectWithTimeout(const char *ip, int port, const struct timeval tv) { + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, ip, port); options.connect_timeout = &tv; - return redisConnectWithOptions(&options); + return redictConnectWithOptions(&options); } -redisContext *redisConnectNonBlock(const char *ip, int port) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, ip, port); - options.options |= REDIS_OPT_NONBLOCK; - return redisConnectWithOptions(&options); +redictContext *redictConnectNonBlock(const char *ip, int port) { + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, ip, port); + options.options |= REDICT_OPT_NONBLOCK; + return redictConnectWithOptions(&options); } -redisContext *redisConnectBindNonBlock(const char *ip, int port, +redictContext *redictConnectBindNonBlock(const char *ip, int port, const char *source_addr) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, ip, port); + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, ip, port); options.endpoint.tcp.source_addr = source_addr; - options.options |= REDIS_OPT_NONBLOCK; - return redisConnectWithOptions(&options); + options.options |= REDICT_OPT_NONBLOCK; + return redictConnectWithOptions(&options); } -redisContext *redisConnectBindNonBlockWithReuse(const char *ip, int port, +redictContext *redictConnectBindNonBlockWithReuse(const char *ip, int port, const char *source_addr) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, ip, port); + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, ip, port); options.endpoint.tcp.source_addr = source_addr; - options.options |= REDIS_OPT_NONBLOCK|REDIS_OPT_REUSEADDR; - return redisConnectWithOptions(&options); + options.options |= REDICT_OPT_NONBLOCK|REDICT_OPT_REUSEADDR; + return redictConnectWithOptions(&options); } -redisContext *redisConnectUnix(const char *path) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_UNIX(&options, path); - return redisConnectWithOptions(&options); +redictContext *redictConnectUnix(const char *path) { + redictOptions options = {0}; + REDICT_OPTIONS_SET_UNIX(&options, path); + return redictConnectWithOptions(&options); } -redisContext *redisConnectUnixWithTimeout(const char *path, const struct timeval tv) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_UNIX(&options, path); +redictContext *redictConnectUnixWithTimeout(const char *path, const struct timeval tv) { + redictOptions options = {0}; + REDICT_OPTIONS_SET_UNIX(&options, path); options.connect_timeout = &tv; - return redisConnectWithOptions(&options); + return redictConnectWithOptions(&options); } -redisContext *redisConnectUnixNonBlock(const char *path) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_UNIX(&options, path); - options.options |= REDIS_OPT_NONBLOCK; - return redisConnectWithOptions(&options); +redictContext *redictConnectUnixNonBlock(const char *path) { + redictOptions options = {0}; + REDICT_OPTIONS_SET_UNIX(&options, path); + options.options |= REDICT_OPT_NONBLOCK; + return redictConnectWithOptions(&options); } -redisContext *redisConnectFd(redisFD fd) { - redisOptions options = {0}; - options.type = REDIS_CONN_USERFD; +redictContext *redictConnectFd(redictFD fd) { + redictOptions options = {0}; + options.type = REDICT_CONN_USERFD; options.endpoint.fd = fd; - return redisConnectWithOptions(&options); + return redictConnectWithOptions(&options); } /* Set read/write timeout on a blocking socket. */ -int redisSetTimeout(redisContext *c, const struct timeval tv) { - if (c->flags & REDIS_BLOCK) - return redisContextSetTimeout(c,tv); - return REDIS_ERR; +int redictSetTimeout(redictContext *c, const struct timeval tv) { + if (c->flags & REDICT_BLOCK) + return redictContextSetTimeout(c,tv); + return REDICT_ERR; } -int redisEnableKeepAliveWithInterval(redisContext *c, int interval) { - return redisKeepAlive(c, interval); +int redictEnableKeepAliveWithInterval(redictContext *c, int interval) { + return redictKeepAlive(c, interval); } /* Enable connection KeepAlive. */ -int redisEnableKeepAlive(redisContext *c) { - return redisKeepAlive(c, REDIS_KEEPALIVE_INTERVAL); +int redictEnableKeepAlive(redictContext *c) { + return redictKeepAlive(c, REDICT_KEEPALIVE_INTERVAL); } /* Set the socket option TCP_USER_TIMEOUT. */ -int redisSetTcpUserTimeout(redisContext *c, unsigned int timeout) { - return redisContextSetTcpUserTimeout(c, timeout); +int redictSetTcpUserTimeout(redictContext *c, unsigned int timeout) { + return redictContextSetTcpUserTimeout(c, timeout); } /* Set a user provided RESP3 PUSH handler and return any old one set. */ -redisPushFn *redisSetPushCallback(redisContext *c, redisPushFn *fn) { - redisPushFn *old = c->push_cb; +redictPushFn *redictSetPushCallback(redictContext *c, redictPushFn *fn) { + redictPushFn *old = c->push_cb; c->push_cb = fn; return old; } @@ -959,46 +959,46 @@ redisPushFn *redisSetPushCallback(redisContext *c, redisPushFn *fn) { /* Use this function to handle a read event on the descriptor. It will try * and read some bytes from the socket and feed them to the reply parser. * - * After this function is called, you may use redisGetReplyFromReader to + * After this function is called, you may use redictGetReplyFromReader to * see if there is a reply available. */ -int redisBufferRead(redisContext *c) { +int redictBufferRead(redictContext *c) { char buf[1024*16]; int nread; /* Return early when the context has seen an error. */ if (c->err) - return REDIS_ERR; + return REDICT_ERR; nread = c->funcs->read(c, buf, sizeof(buf)); if (nread < 0) { - return REDIS_ERR; + return REDICT_ERR; } - if (nread > 0 && redisReaderFeed(c->reader, buf, nread) != REDIS_OK) { - __redisSetError(c, c->reader->err, c->reader->errstr); - return REDIS_ERR; + if (nread > 0 && redictReaderFeed(c->reader, buf, nread) != REDICT_OK) { + __redictSetError(c, c->reader->err, c->reader->errstr); + return REDICT_ERR; } - return REDIS_OK; + return REDICT_OK; } /* Write the output buffer to the socket. * - * Returns REDIS_OK when the buffer is empty, or (a part of) the buffer was + * Returns REDICT_OK when the buffer is empty, or (a part of) the buffer was * successfully written to the socket. When the buffer is empty after the * write operation, "done" is set to 1 (if given). * - * Returns REDIS_ERR if an unrecoverable error occurred in the underlying + * Returns REDICT_ERR if an unrecoverable error occurred in the underlying * c->funcs->write function. */ -int redisBufferWrite(redisContext *c, int *done) { +int redictBufferWrite(redictContext *c, int *done) { /* Return early when the context has seen an error. */ if (c->err) - return REDIS_ERR; + return REDICT_ERR; if (sdslen(c->obuf) > 0) { ssize_t nwritten = c->funcs->write(c); if (nwritten < 0) { - return REDIS_ERR; + return REDICT_ERR; } else if (nwritten > 0) { if (nwritten == (ssize_t)sdslen(c->obuf)) { sdsfree(c->obuf); @@ -1011,17 +1011,17 @@ int redisBufferWrite(redisContext *c, int *done) { } } if (done != NULL) *done = (sdslen(c->obuf) == 0); - return REDIS_OK; + return REDICT_OK; oom: - __redisSetError(c, REDIS_ERR_OOM, "Out of memory"); - return REDIS_ERR; + __redictSetError(c, REDICT_ERR_OOM, "Out of memory"); + return REDICT_ERR; } /* Internal helper that returns 1 if the reply was a RESP3 PUSH * message and we handled it with a user-provided callback. */ -static int redisHandledPushReply(redisContext *c, void *reply) { - if (reply && c->push_cb && redisIsPushReply(reply)) { +static int redictHandledPushReply(redictContext *c, void *reply) { + if (reply && c->push_cb && redictIsPushReply(reply)) { c->push_cb(c->privdata, reply); return 1; } @@ -1030,50 +1030,50 @@ static int redisHandledPushReply(redisContext *c, void *reply) { } /* Get a reply from our reader or set an error in the context. */ -int redisGetReplyFromReader(redisContext *c, void **reply) { - if (redisReaderGetReply(c->reader, reply) == REDIS_ERR) { - __redisSetError(c,c->reader->err,c->reader->errstr); - return REDIS_ERR; +int redictGetReplyFromReader(redictContext *c, void **reply) { + if (redictReaderGetReply(c->reader, reply) == REDICT_ERR) { + __redictSetError(c,c->reader->err,c->reader->errstr); + return REDICT_ERR; } - return REDIS_OK; + return REDICT_OK; } /* Internal helper to get the next reply from our reader while handling * any PUSH messages we encounter along the way. This is separate from - * redisGetReplyFromReader so as to not change its behavior. */ -static int redisNextInBandReplyFromReader(redisContext *c, void **reply) { + * redictGetReplyFromReader so as to not change its behavior. */ +static int redictNextInBandReplyFromReader(redictContext *c, void **reply) { do { - if (redisGetReplyFromReader(c, reply) == REDIS_ERR) - return REDIS_ERR; - } while (redisHandledPushReply(c, *reply)); + if (redictGetReplyFromReader(c, reply) == REDICT_ERR) + return REDICT_ERR; + } while (redictHandledPushReply(c, *reply)); - return REDIS_OK; + return REDICT_OK; } -int redisGetReply(redisContext *c, void **reply) { +int redictGetReply(redictContext *c, void **reply) { int wdone = 0; void *aux = NULL; /* Try to read pending replies */ - if (redisNextInBandReplyFromReader(c,&aux) == REDIS_ERR) - return REDIS_ERR; + if (redictNextInBandReplyFromReader(c,&aux) == REDICT_ERR) + return REDICT_ERR; /* For the blocking context, flush output buffer and read reply */ - if (aux == NULL && c->flags & REDIS_BLOCK) { + if (aux == NULL && c->flags & REDICT_BLOCK) { /* Write until done */ do { - if (redisBufferWrite(c,&wdone) == REDIS_ERR) - return REDIS_ERR; + if (redictBufferWrite(c,&wdone) == REDICT_ERR) + return REDICT_ERR; } while (!wdone); /* Read until there is a reply */ do { - if (redisBufferRead(c) == REDIS_ERR) - return REDIS_ERR; + if (redictBufferRead(c) == REDICT_ERR) + return REDICT_ERR; - if (redisNextInBandReplyFromReader(c,&aux) == REDIS_ERR) - return REDIS_ERR; + if (redictNextInBandReplyFromReader(c,&aux) == REDICT_ERR) + return REDICT_ERR; } while (aux == NULL); } @@ -1084,90 +1084,90 @@ int redisGetReply(redisContext *c, void **reply) { freeReplyObject(aux); } - return REDIS_OK; + return REDICT_OK; } -/* Helper function for the redisAppendCommand* family of functions. +/* Helper function for the redictAppendCommand* family of functions. * * Write a formatted command to the output buffer. When this family - * is used, you need to call redisGetReply yourself to retrieve + * is used, you need to call redictGetReply yourself to retrieve * the reply (or replies in pub/sub). */ -int __redisAppendCommand(redisContext *c, const char *cmd, size_t len) { +int __redictAppendCommand(redictContext *c, const char *cmd, size_t len) { sds newbuf; newbuf = sdscatlen(c->obuf,cmd,len); if (newbuf == NULL) { - __redisSetError(c,REDIS_ERR_OOM,"Out of memory"); - return REDIS_ERR; + __redictSetError(c,REDICT_ERR_OOM,"Out of memory"); + return REDICT_ERR; } c->obuf = newbuf; - return REDIS_OK; + return REDICT_OK; } -int redisAppendFormattedCommand(redisContext *c, const char *cmd, size_t len) { +int redictAppendFormattedCommand(redictContext *c, const char *cmd, size_t len) { - if (__redisAppendCommand(c, cmd, len) != REDIS_OK) { - return REDIS_ERR; + if (__redictAppendCommand(c, cmd, len) != REDICT_OK) { + return REDICT_ERR; } - return REDIS_OK; + return REDICT_OK; } -int redisvAppendCommand(redisContext *c, const char *format, va_list ap) { +int redictvAppendCommand(redictContext *c, const char *format, va_list ap) { char *cmd; int len; - len = redisvFormatCommand(&cmd,format,ap); + len = redictvFormatCommand(&cmd,format,ap); if (len == -1) { - __redisSetError(c,REDIS_ERR_OOM,"Out of memory"); - return REDIS_ERR; + __redictSetError(c,REDICT_ERR_OOM,"Out of memory"); + return REDICT_ERR; } else if (len == -2) { - __redisSetError(c,REDIS_ERR_OTHER,"Invalid format string"); - return REDIS_ERR; + __redictSetError(c,REDICT_ERR_OTHER,"Invalid format string"); + return REDICT_ERR; } - if (__redisAppendCommand(c,cmd,len) != REDIS_OK) { + if (__redictAppendCommand(c,cmd,len) != REDICT_OK) { hi_free(cmd); - return REDIS_ERR; + return REDICT_ERR; } hi_free(cmd); - return REDIS_OK; + return REDICT_OK; } -int redisAppendCommand(redisContext *c, const char *format, ...) { +int redictAppendCommand(redictContext *c, const char *format, ...) { va_list ap; int ret; va_start(ap,format); - ret = redisvAppendCommand(c,format,ap); + ret = redictvAppendCommand(c,format,ap); va_end(ap); return ret; } -int redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen) { +int redictAppendCommandArgv(redictContext *c, int argc, const char **argv, const size_t *argvlen) { sds cmd; long long len; - len = redisFormatSdsCommandArgv(&cmd,argc,argv,argvlen); + len = redictFormatSdsCommandArgv(&cmd,argc,argv,argvlen); if (len == -1) { - __redisSetError(c,REDIS_ERR_OOM,"Out of memory"); - return REDIS_ERR; + __redictSetError(c,REDICT_ERR_OOM,"Out of memory"); + return REDICT_ERR; } - if (__redisAppendCommand(c,cmd,len) != REDIS_OK) { + if (__redictAppendCommand(c,cmd,len) != REDICT_OK) { sdsfree(cmd); - return REDIS_ERR; + return REDICT_ERR; } sdsfree(cmd); - return REDIS_OK; + return REDICT_OK; } -/* Helper function for the redisCommand* family of functions. +/* Helper function for the redictCommand* family of functions. * * Write a formatted command to the output buffer. If the given context is * blocking, immediately read the reply into the "reply" pointer. When the @@ -1178,33 +1178,33 @@ int redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const s * otherwise. When NULL is returned in a blocking context, the error field * in the context will be set. */ -static void *__redisBlockForReply(redisContext *c) { +static void *__redictBlockForReply(redictContext *c) { void *reply; - if (c->flags & REDIS_BLOCK) { - if (redisGetReply(c,&reply) != REDIS_OK) + if (c->flags & REDICT_BLOCK) { + if (redictGetReply(c,&reply) != REDICT_OK) return NULL; return reply; } return NULL; } -void *redisvCommand(redisContext *c, const char *format, va_list ap) { - if (redisvAppendCommand(c,format,ap) != REDIS_OK) +void *redictvCommand(redictContext *c, const char *format, va_list ap) { + if (redictvAppendCommand(c,format,ap) != REDICT_OK) return NULL; - return __redisBlockForReply(c); + return __redictBlockForReply(c); } -void *redisCommand(redisContext *c, const char *format, ...) { +void *redictCommand(redictContext *c, const char *format, ...) { va_list ap; va_start(ap,format); - void *reply = redisvCommand(c,format,ap); + void *reply = redictvCommand(c,format,ap); va_end(ap); return reply; } -void *redisCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen) { - if (redisAppendCommandArgv(c,argc,argv,argvlen) != REDIS_OK) +void *redictCommandArgv(redictContext *c, int argc, const char **argv, const size_t *argvlen) { + if (redictAppendCommandArgv(c,argc,argv,argvlen) != REDICT_OK) return NULL; - return __redisBlockForReply(c); + return __redictBlockForReply(c); } diff --git a/hiredict.h b/hiredict.h index 1936b4d..c186bb7 100644 --- a/hiredict.h +++ b/hiredict.h @@ -15,8 +15,8 @@ * */ -#ifndef __HIREDIS_H -#define __HIREDIS_H +#ifndef __HIREDICT_H +#define __HIREDICT_H #include "read.h" #include /* for va_list */ #ifndef _MSC_VER @@ -29,141 +29,141 @@ typedef long long ssize_t; #include "sds.h" /* for sds */ #include "alloc.h" /* for allocation wrappers */ -#define HIREDIS_MAJOR 1 -#define HIREDIS_MINOR 2 -#define HIREDIS_PATCH 0 -#define HIREDIS_SONAME 1.2.1-dev +#define HIREDICT_MAJOR 1 +#define HIREDICT_MINOR 2 +#define HIREDICT_PATCH 0 +#define HIREDICT_SONAME 1.2.1-dev /* Connection type can be blocking or non-blocking and is set in the - * least significant bit of the flags field in redisContext. */ -#define REDIS_BLOCK 0x1 + * least significant bit of the flags field in redictContext. */ +#define REDICT_BLOCK 0x1 /* Connection may be disconnected before being free'd. The second bit * in the flags field is set when the context is connected. */ -#define REDIS_CONNECTED 0x2 +#define REDICT_CONNECTED 0x2 /* The async API might try to disconnect cleanly and flush the output * buffer and read all subsequent replies before disconnecting. * This flag means no new commands can come in and the connection * should be terminated once all replies have been read. */ -#define REDIS_DISCONNECTING 0x4 +#define REDICT_DISCONNECTING 0x4 /* Flag specific to the async API which means that the context should be clean * up as soon as possible. */ -#define REDIS_FREEING 0x8 +#define REDICT_FREEING 0x8 /* Flag that is set when an async callback is executed. */ -#define REDIS_IN_CALLBACK 0x10 +#define REDICT_IN_CALLBACK 0x10 /* Flag that is set when the async context has one or more subscriptions. */ -#define REDIS_SUBSCRIBED 0x20 +#define REDICT_SUBSCRIBED 0x20 /* Flag that is set when monitor mode is active */ -#define REDIS_MONITORING 0x40 +#define REDICT_MONITORING 0x40 /* Flag that is set when we should set SO_REUSEADDR before calling bind() */ -#define REDIS_REUSEADDR 0x80 +#define REDICT_REUSEADDR 0x80 /* Flag that is set when the async connection supports push replies. */ -#define REDIS_SUPPORTS_PUSH 0x100 +#define REDICT_SUPPORTS_PUSH 0x100 /** * Flag that indicates the user does not want the context to * be automatically freed upon error */ -#define REDIS_NO_AUTO_FREE 0x200 +#define REDICT_NO_AUTO_FREE 0x200 /* Flag that indicates the user does not want replies to be automatically freed */ -#define REDIS_NO_AUTO_FREE_REPLIES 0x400 +#define REDICT_NO_AUTO_FREE_REPLIES 0x400 /* Flags to prefer IPv6 or IPv4 when doing DNS lookup. (If both are set, * AF_UNSPEC is used.) */ -#define REDIS_PREFER_IPV4 0x800 -#define REDIS_PREFER_IPV6 0x1000 +#define REDICT_PREFER_IPV4 0x800 +#define REDICT_PREFER_IPV6 0x1000 -#define REDIS_KEEPALIVE_INTERVAL 15 /* seconds */ +#define REDICT_KEEPALIVE_INTERVAL 15 /* seconds */ /* number of times we retry to connect in the case of EADDRNOTAVAIL and * SO_REUSEADDR is being used. */ -#define REDIS_CONNECT_RETRIES 10 +#define REDICT_CONNECT_RETRIES 10 /* Forward declarations for structs defined elsewhere */ -struct redisAsyncContext; -struct redisContext; +struct redictAsyncContext; +struct redictContext; /* RESP3 push helpers and callback prototypes */ -#define redisIsPushReply(r) (((redisReply*)(r))->type == REDIS_REPLY_PUSH) -typedef void (redisPushFn)(void *, void *); -typedef void (redisAsyncPushFn)(struct redisAsyncContext *, void *); +#define redictIsPushReply(r) (((redictReply*)(r))->type == REDICT_REPLY_PUSH) +typedef void (redictPushFn)(void *, void *); +typedef void (redictAsyncPushFn)(struct redictAsyncContext *, void *); #ifdef __cplusplus extern "C" { #endif -/* This is the reply object returned by redisCommand() */ -typedef struct redisReply { - int type; /* REDIS_REPLY_* */ - long long integer; /* The integer when type is REDIS_REPLY_INTEGER */ - double dval; /* The double when type is REDIS_REPLY_DOUBLE */ +/* This is the reply object returned by redictCommand() */ +typedef struct redictReply { + int type; /* REDICT_REPLY_* */ + long long integer; /* The integer when type is REDICT_REPLY_INTEGER */ + double dval; /* The double when type is REDICT_REPLY_DOUBLE */ size_t len; /* Length of string */ - char *str; /* Used for REDIS_REPLY_ERROR, REDIS_REPLY_STRING - REDIS_REPLY_VERB, REDIS_REPLY_DOUBLE (in additional to dval), - and REDIS_REPLY_BIGNUM. */ - char vtype[4]; /* Used for REDIS_REPLY_VERB, contains the null + char *str; /* Used for REDICT_REPLY_ERROR, REDICT_REPLY_STRING + REDICT_REPLY_VERB, REDICT_REPLY_DOUBLE (in additional to dval), + and REDICT_REPLY_BIGNUM. */ + char vtype[4]; /* Used for REDICT_REPLY_VERB, contains the null terminated 3 character content type, such as "txt". */ - size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */ - struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */ -} redisReply; + size_t elements; /* number of elements, for REDICT_REPLY_ARRAY */ + struct redictReply **element; /* elements vector for REDICT_REPLY_ARRAY */ +} redictReply; -redisReader *redisReaderCreate(void); +redictReader *redictReaderCreate(void); -/* Function to free the reply objects hiredis returns by default. */ +/* Function to free the reply objects hiredict returns by default. */ void freeReplyObject(void *reply); /* Functions to format a command according to the protocol. */ -int redisvFormatCommand(char **target, const char *format, va_list ap); -int redisFormatCommand(char **target, const char *format, ...); -long long redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen); -long long redisFormatSdsCommandArgv(sds *target, int argc, const char ** argv, const size_t *argvlen); -void redisFreeCommand(char *cmd); -void redisFreeSdsCommand(sds cmd); - -enum redisConnectionType { - REDIS_CONN_TCP, - REDIS_CONN_UNIX, - REDIS_CONN_USERFD +int redictvFormatCommand(char **target, const char *format, va_list ap); +int redictFormatCommand(char **target, const char *format, ...); +long long redictFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen); +long long redictFormatSdsCommandArgv(sds *target, int argc, const char ** argv, const size_t *argvlen); +void redictFreeCommand(char *cmd); +void redictFreeSdsCommand(sds cmd); + +enum redictConnectionType { + REDICT_CONN_TCP, + REDICT_CONN_UNIX, + REDICT_CONN_USERFD }; -struct redisSsl; +struct redictSsl; -#define REDIS_OPT_NONBLOCK 0x01 -#define REDIS_OPT_REUSEADDR 0x02 -#define REDIS_OPT_NOAUTOFREE 0x04 /* Don't automatically free the async +#define REDICT_OPT_NONBLOCK 0x01 +#define REDICT_OPT_REUSEADDR 0x02 +#define REDICT_OPT_NOAUTOFREE 0x04 /* Don't automatically free the async * object on a connection failure, or * other implicit conditions. Only free * on an explicit call to disconnect() * or free() */ -#define REDIS_OPT_NO_PUSH_AUTOFREE 0x08 /* Don't automatically intercept and +#define REDICT_OPT_NO_PUSH_AUTOFREE 0x08 /* Don't automatically intercept and * free RESP3 PUSH replies. */ -#define REDIS_OPT_NOAUTOFREEREPLIES 0x10 /* Don't automatically free replies. */ -#define REDIS_OPT_PREFER_IPV4 0x20 /* Prefer IPv4 in DNS lookups. */ -#define REDIS_OPT_PREFER_IPV6 0x40 /* Prefer IPv6 in DNS lookups. */ -#define REDIS_OPT_PREFER_IP_UNSPEC (REDIS_OPT_PREFER_IPV4 | REDIS_OPT_PREFER_IPV6) +#define REDICT_OPT_NOAUTOFREEREPLIES 0x10 /* Don't automatically free replies. */ +#define REDICT_OPT_PREFER_IPV4 0x20 /* Prefer IPv4 in DNS lookups. */ +#define REDICT_OPT_PREFER_IPV6 0x40 /* Prefer IPv6 in DNS lookups. */ +#define REDICT_OPT_PREFER_IP_UNSPEC (REDICT_OPT_PREFER_IPV4 | REDICT_OPT_PREFER_IPV6) /* In Unix systems a file descriptor is a regular signed int, with -1 * representing an invalid descriptor. In Windows it is a SOCKET * (32- or 64-bit unsigned integer depending on the architecture), where * all bits set (~0) is INVALID_SOCKET. */ #ifndef _WIN32 -typedef int redisFD; -#define REDIS_INVALID_FD -1 +typedef int redictFD; +#define REDICT_INVALID_FD -1 #else #ifdef _WIN64 -typedef unsigned long long redisFD; /* SOCKET = 64-bit UINT_PTR */ +typedef unsigned long long redictFD; /* SOCKET = 64-bit UINT_PTR */ #else -typedef unsigned long redisFD; /* SOCKET = 32-bit UINT_PTR */ +typedef unsigned long redictFD; /* SOCKET = 32-bit UINT_PTR */ #endif -#define REDIS_INVALID_FD ((redisFD)(~0)) /* INVALID_SOCKET */ +#define REDICT_INVALID_FD ((redictFD)(~0)) /* INVALID_SOCKET */ #endif typedef struct { @@ -172,12 +172,12 @@ typedef struct { * `endpoint` member field to use */ int type; - /* bit field of REDIS_OPT_xxx */ + /* bit field of REDICT_OPT_xxx */ int options; /* timeout value for connect operation. If NULL, no timeout is used */ const struct timeval *connect_timeout; /* timeout value for commands. If NULL, no timeout is used. This can be - * updated at runtime with redisSetTimeout/redisAsyncSetTimeout. */ + * updated at runtime with redictSetTimeout/redictAsyncSetTimeout. */ const struct timeval *command_timeout; union { /** use this field for tcp/ip connections */ @@ -189,9 +189,9 @@ typedef struct { /** use this field for unix domain sockets */ const char *unix_socket; /** - * use this field to have hiredis operate an already-open + * use this field to have hiredict operate an already-open * file descriptor */ - redisFD fd; + redictFD fd; } endpoint; /* Optional user defined data/destructor */ @@ -199,56 +199,56 @@ typedef struct { void (*free_privdata)(void *); /* A user defined PUSH message callback */ - redisPushFn *push_cb; - redisAsyncPushFn *async_push_cb; -} redisOptions; + redictPushFn *push_cb; + redictAsyncPushFn *async_push_cb; +} redictOptions; /** * Helper macros to initialize options to their specified fields. */ -#define REDIS_OPTIONS_SET_TCP(opts, ip_, port_) do { \ - (opts)->type = REDIS_CONN_TCP; \ +#define REDICT_OPTIONS_SET_TCP(opts, ip_, port_) do { \ + (opts)->type = REDICT_CONN_TCP; \ (opts)->endpoint.tcp.ip = ip_; \ (opts)->endpoint.tcp.port = port_; \ } while(0) -#define REDIS_OPTIONS_SET_UNIX(opts, path) do { \ - (opts)->type = REDIS_CONN_UNIX; \ +#define REDICT_OPTIONS_SET_UNIX(opts, path) do { \ + (opts)->type = REDICT_CONN_UNIX; \ (opts)->endpoint.unix_socket = path; \ } while(0) -#define REDIS_OPTIONS_SET_PRIVDATA(opts, data, dtor) do { \ +#define REDICT_OPTIONS_SET_PRIVDATA(opts, data, dtor) do { \ (opts)->privdata = data; \ (opts)->free_privdata = dtor; \ } while(0) -typedef struct redisContextFuncs { - void (*close)(struct redisContext *); +typedef struct redictContextFuncs { + void (*close)(struct redictContext *); void (*free_privctx)(void *); - void (*async_read)(struct redisAsyncContext *); - void (*async_write)(struct redisAsyncContext *); + void (*async_read)(struct redictAsyncContext *); + void (*async_write)(struct redictAsyncContext *); /* Read/Write data to the underlying communication stream, returning the * number of bytes read/written. In the event of an unrecoverable error * these functions shall return a value < 0. In the event of a * recoverable error, they should return 0. */ - ssize_t (*read)(struct redisContext *, char *, size_t); - ssize_t (*write)(struct redisContext *); -} redisContextFuncs; + ssize_t (*read)(struct redictContext *, char *, size_t); + ssize_t (*write)(struct redictContext *); +} redictContextFuncs; -/* Context for a connection to Redis */ -typedef struct redisContext { - const redisContextFuncs *funcs; /* Function table */ +/* Context for a connection to Redict */ +typedef struct redictContext { + const redictContextFuncs *funcs; /* Function table */ int err; /* Error flags, 0 when there is no error */ char errstr[128]; /* String representation of error when applicable */ - redisFD fd; + redictFD fd; int flags; char *obuf; /* Write buffer */ - redisReader *reader; /* Protocol reader */ + redictReader *reader; /* Protocol reader */ - enum redisConnectionType connection_type; + enum redictConnectionType connection_type; struct timeval *connect_timeout; struct timeval *command_timeout; @@ -267,30 +267,30 @@ typedef struct redisContext { size_t addrlen; /* Optional data and corresponding destructor users can use to provide - * context to a given redisContext. Not used by hiredis. */ + * context to a given redictContext. Not used by hiredict. */ void *privdata; void (*free_privdata)(void *); - /* Internal context pointer presently used by hiredis to manage + /* Internal context pointer presently used by hiredict to manage * SSL connections. */ void *privctx; /* An optional RESP3 PUSH handler */ - redisPushFn *push_cb; -} redisContext; - -redisContext *redisConnectWithOptions(const redisOptions *options); -redisContext *redisConnect(const char *ip, int port); -redisContext *redisConnectWithTimeout(const char *ip, int port, const struct timeval tv); -redisContext *redisConnectNonBlock(const char *ip, int port); -redisContext *redisConnectBindNonBlock(const char *ip, int port, + redictPushFn *push_cb; +} redictContext; + +redictContext *redictConnectWithOptions(const redictOptions *options); +redictContext *redictConnect(const char *ip, int port); +redictContext *redictConnectWithTimeout(const char *ip, int port, const struct timeval tv); +redictContext *redictConnectNonBlock(const char *ip, int port); +redictContext *redictConnectBindNonBlock(const char *ip, int port, const char *source_addr); -redisContext *redisConnectBindNonBlockWithReuse(const char *ip, int port, +redictContext *redictConnectBindNonBlockWithReuse(const char *ip, int port, const char *source_addr); -redisContext *redisConnectUnix(const char *path); -redisContext *redisConnectUnixWithTimeout(const char *path, const struct timeval tv); -redisContext *redisConnectUnixNonBlock(const char *path); -redisContext *redisConnectFd(redisFD fd); +redictContext *redictConnectUnix(const char *path); +redictContext *redictConnectUnixWithTimeout(const char *path, const struct timeval tv); +redictContext *redictConnectUnixNonBlock(const char *path); +redictContext *redictConnectFd(redictFD fd); /** * Reconnect the given context using the saved information. @@ -299,45 +299,45 @@ redisContext *redisConnectFd(redisFD fd); * host, ip (or path), timeout and bind address are reused, * flags are used unmodified from the existing context. * - * Returns REDIS_OK on successful connect or REDIS_ERR otherwise. + * Returns REDICT_OK on successful connect or REDICT_ERR otherwise. */ -int redisReconnect(redisContext *c); - -redisPushFn *redisSetPushCallback(redisContext *c, redisPushFn *fn); -int redisSetTimeout(redisContext *c, const struct timeval tv); -int redisEnableKeepAlive(redisContext *c); -int redisEnableKeepAliveWithInterval(redisContext *c, int interval); -int redisSetTcpUserTimeout(redisContext *c, unsigned int timeout); -void redisFree(redisContext *c); -redisFD redisFreeKeepFd(redisContext *c); -int redisBufferRead(redisContext *c); -int redisBufferWrite(redisContext *c, int *done); +int redictReconnect(redictContext *c); + +redictPushFn *redictSetPushCallback(redictContext *c, redictPushFn *fn); +int redictSetTimeout(redictContext *c, const struct timeval tv); +int redictEnableKeepAlive(redictContext *c); +int redictEnableKeepAliveWithInterval(redictContext *c, int interval); +int redictSetTcpUserTimeout(redictContext *c, unsigned int timeout); +void redictFree(redictContext *c); +redictFD redictFreeKeepFd(redictContext *c); +int redictBufferRead(redictContext *c); +int redictBufferWrite(redictContext *c, int *done); /* In a blocking context, this function first checks if there are unconsumed * replies to return and returns one if so. Otherwise, it flushes the output * buffer to the socket and reads until it has a reply. In a non-blocking * context, it will return unconsumed replies until there are no more. */ -int redisGetReply(redisContext *c, void **reply); -int redisGetReplyFromReader(redisContext *c, void **reply); +int redictGetReply(redictContext *c, void **reply); +int redictGetReplyFromReader(redictContext *c, void **reply); /* Write a formatted command to the output buffer. Use these functions in blocking mode * to get a pipeline of commands. */ -int redisAppendFormattedCommand(redisContext *c, const char *cmd, size_t len); +int redictAppendFormattedCommand(redictContext *c, const char *cmd, size_t len); /* Write a command to the output buffer. Use these functions in blocking mode * to get a pipeline of commands. */ -int redisvAppendCommand(redisContext *c, const char *format, va_list ap); -int redisAppendCommand(redisContext *c, const char *format, ...); -int redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen); +int redictvAppendCommand(redictContext *c, const char *format, va_list ap); +int redictAppendCommand(redictContext *c, const char *format, ...); +int redictAppendCommandArgv(redictContext *c, int argc, const char **argv, const size_t *argvlen); -/* Issue a command to Redis. In a blocking context, it is identical to calling - * redisAppendCommand, followed by redisGetReply. The function will return +/* Issue a command to Redict. In a blocking context, it is identical to calling + * redictAppendCommand, followed by redictGetReply. The function will return * NULL if there was an error in performing the request, otherwise it will * return the reply. In a non-blocking context, it is identical to calling - * only redisAppendCommand and will always return NULL. */ -void *redisvCommand(redisContext *c, const char *format, va_list ap); -void *redisCommand(redisContext *c, const char *format, ...); -void *redisCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen); + * only redictAppendCommand and will always return NULL. */ +void *redictvCommand(redictContext *c, const char *format, va_list ap); +void *redictCommand(redictContext *c, const char *format, ...); +void *redictCommandArgv(redictContext *c, int argc, const char **argv, const size_t *argvlen); #ifdef __cplusplus } diff --git a/hiredict.pc.in b/hiredict.pc.in index c7b8e0e..3c8bab1 100644 --- a/hiredict.pc.in +++ b/hiredict.pc.in @@ -3,10 +3,10 @@ install_libdir=@CMAKE_INSTALL_LIBDIR@ exec_prefix=${prefix} libdir=${exec_prefix}/${install_libdir} includedir=${prefix}/include -pkgincludedir=${includedir}/hiredis +pkgincludedir=${includedir}/hiredict -Name: hiredis -Description: Minimalistic C client library for Redis. +Name: hiredict +Description: Minimalistic C client library for Redict. Version: @PROJECT_VERSION@ -Libs: -L${libdir} -lhiredis +Libs: -L${libdir} -lhiredict Cflags: -I${pkgincludedir} -I${includedir} -D_FILE_OFFSET_BITS=64 diff --git a/hiredict_ssl-config.cmake.in b/hiredict_ssl-config.cmake.in index eeb19d1..706aea2 100644 --- a/hiredict_ssl-config.cmake.in +++ b/hiredict_ssl-config.cmake.in @@ -1,16 +1,16 @@ @PACKAGE_INIT@ -set_and_check(hiredis_ssl_INCLUDEDIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(hiredict_ssl_INCLUDEDIR "@PACKAGE_INCLUDE_INSTALL_DIR@") include(CMakeFindDependencyMacro) find_dependency(OpenSSL) -IF (NOT TARGET hiredis::hiredis_ssl) - INCLUDE(${CMAKE_CURRENT_LIST_DIR}/hiredis_ssl-targets.cmake) +IF (NOT TARGET hiredict::hiredict_ssl) + INCLUDE(${CMAKE_CURRENT_LIST_DIR}/hiredict_ssl-targets.cmake) ENDIF() -SET(hiredis_ssl_LIBRARIES hiredis::hiredis_ssl) -SET(hiredis_ssl_INCLUDE_DIRS ${hiredis_ssl_INCLUDEDIR}) +SET(hiredict_ssl_LIBRARIES hiredict::hiredict_ssl) +SET(hiredict_ssl_INCLUDE_DIRS ${hiredict_ssl_INCLUDEDIR}) -check_required_components(hiredis_ssl) +check_required_components(hiredict_ssl) diff --git a/hiredict_ssl.h b/hiredict_ssl.h index 43f072a..73aa3c3 100644 --- a/hiredict_ssl.h +++ b/hiredict_ssl.h @@ -1,16 +1,16 @@ /* - * Copyright (c) 2019, Redis Labs + * Copyright (c) 2019, Redict Labs * * SPDX-FileCopyrightText: 2024 Hiredict Contributors - * SPDX-FileCopyrightText: 2024 Redis Labs + * SPDX-FileCopyrightText: 2024 Redict Labs * * SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: LGPL-3.0-or-later * */ -#ifndef __HIREDIS_SSL_H -#define __HIREDIS_SSL_H +#ifndef __HIREDICT_SSL_H +#define __HIREDICT_SSL_H #ifdef __cplusplus extern "C" { @@ -24,34 +24,34 @@ struct ssl_st; /* A wrapper around OpenSSL SSL_CTX to allow easy SSL use without directly * calling OpenSSL. */ -typedef struct redisSSLContext redisSSLContext; +typedef struct redictSSLContext redictSSLContext; /** - * Initialization errors that redisCreateSSLContext() may return. + * Initialization errors that redictCreateSSLContext() may return. */ typedef enum { - REDIS_SSL_CTX_NONE = 0, /* No Error */ - REDIS_SSL_CTX_CREATE_FAILED, /* Failed to create OpenSSL SSL_CTX */ - REDIS_SSL_CTX_CERT_KEY_REQUIRED, /* Client cert and key must both be specified or skipped */ - REDIS_SSL_CTX_CA_CERT_LOAD_FAILED, /* Failed to load CA Certificate or CA Path */ - REDIS_SSL_CTX_CLIENT_CERT_LOAD_FAILED, /* Failed to load client certificate */ - REDIS_SSL_CTX_CLIENT_DEFAULT_CERT_FAILED, /* Failed to set client default certificate directory */ - REDIS_SSL_CTX_PRIVATE_KEY_LOAD_FAILED, /* Failed to load private key */ - REDIS_SSL_CTX_OS_CERTSTORE_OPEN_FAILED, /* Failed to open system certificate store */ - REDIS_SSL_CTX_OS_CERT_ADD_FAILED /* Failed to add CA certificates obtained from system to the SSL context */ -} redisSSLContextError; + REDICT_SSL_CTX_NONE = 0, /* No Error */ + REDICT_SSL_CTX_CREATE_FAILED, /* Failed to create OpenSSL SSL_CTX */ + REDICT_SSL_CTX_CERT_KEY_REQUIRED, /* Client cert and key must both be specified or skipped */ + REDICT_SSL_CTX_CA_CERT_LOAD_FAILED, /* Failed to load CA Certificate or CA Path */ + REDICT_SSL_CTX_CLIENT_CERT_LOAD_FAILED, /* Failed to load client certificate */ + REDICT_SSL_CTX_CLIENT_DEFAULT_CERT_FAILED, /* Failed to set client default certificate directory */ + REDICT_SSL_CTX_PRIVATE_KEY_LOAD_FAILED, /* Failed to load private key */ + REDICT_SSL_CTX_OS_CERTSTORE_OPEN_FAILED, /* Failed to open system certificate store */ + REDICT_SSL_CTX_OS_CERT_ADD_FAILED /* Failed to add CA certificates obtained from system to the SSL context */ +} redictSSLContextError; /* Constants that mirror OpenSSL's verify modes. By default, - * REDIS_SSL_VERIFY_PEER is used with redisCreateSSLContext(). - * Some Redis clients disable peer verification if there are no + * REDICT_SSL_VERIFY_PEER is used with redictCreateSSLContext(). + * Some Redict clients disable peer verification if there are no * certificates specified. */ -#define REDIS_SSL_VERIFY_NONE 0x00 -#define REDIS_SSL_VERIFY_PEER 0x01 -#define REDIS_SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02 -#define REDIS_SSL_VERIFY_CLIENT_ONCE 0x04 -#define REDIS_SSL_VERIFY_POST_HANDSHAKE 0x08 +#define REDICT_SSL_VERIFY_NONE 0x00 +#define REDICT_SSL_VERIFY_PEER 0x01 +#define REDICT_SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02 +#define REDICT_SSL_VERIFY_CLIENT_ONCE 0x04 +#define REDICT_SSL_VERIFY_POST_HANDSHAKE 0x08 /* Options to create an OpenSSL context. */ typedef struct { @@ -61,13 +61,13 @@ typedef struct { const char *private_key_filename; const char *server_name; int verify_mode; -} redisSSLOptions; +} redictSSLOptions; /** * Return the error message corresponding with the specified error code. */ -const char *redisSSLContextGetError(redisSSLContextError error); +const char *redictSSLContextGetError(redictSSLContextError error); /** * Helper function to initialize the OpenSSL library. @@ -76,7 +76,7 @@ const char *redisSSLContextGetError(redisSSLContextError error); * call this function only once, and only if OpenSSL is not directly initialized * elsewhere. */ -int redisInitOpenSSL(void); +int redictInitOpenSSL(void); /** * Helper function to initialize an OpenSSL context that can be used @@ -99,45 +99,45 @@ int redisInitOpenSSL(void); * (returning a NULL). */ -redisSSLContext *redisCreateSSLContext(const char *cacert_filename, const char *capath, +redictSSLContext *redictCreateSSLContext(const char *cacert_filename, const char *capath, const char *cert_filename, const char *private_key_filename, - const char *server_name, redisSSLContextError *error); + const char *server_name, redictSSLContextError *error); /** * Helper function to initialize an OpenSSL context that can be used - * to initiate SSL connections. This is a more extensible version of redisCreateSSLContext(). + * to initiate SSL connections. This is a more extensible version of redictCreateSSLContext(). * * options contains a structure of SSL options to use. * * If error is non-null, it will be populated in case the context creation fails * (returning a NULL). */ -redisSSLContext *redisCreateSSLContextWithOptions(redisSSLOptions *options, - redisSSLContextError *error); +redictSSLContext *redictCreateSSLContextWithOptions(redictSSLOptions *options, + redictSSLContextError *error); /** * Free a previously created OpenSSL context. */ -void redisFreeSSLContext(redisSSLContext *redis_ssl_ctx); +void redictFreeSSLContext(redictSSLContext *redict_ssl_ctx); /** - * Initiate SSL on an existing redisContext. + * Initiate SSL on an existing redictContext. * - * This is similar to redisInitiateSSL() but does not require the caller - * to directly interact with OpenSSL, and instead uses a redisSSLContext - * previously created using redisCreateSSLContext(). + * This is similar to redictInitiateSSL() but does not require the caller + * to directly interact with OpenSSL, and instead uses a redictSSLContext + * previously created using redictCreateSSLContext(). */ -int redisInitiateSSLWithContext(redisContext *c, redisSSLContext *redis_ssl_ctx); +int redictInitiateSSLWithContext(redictContext *c, redictSSLContext *redict_ssl_ctx); /** * Initiate SSL/TLS negotiation on a provided OpenSSL SSL object. */ -int redisInitiateSSL(redisContext *c, struct ssl_st *ssl); +int redictInitiateSSL(redictContext *c, struct ssl_st *ssl); #ifdef __cplusplus } #endif -#endif /* __HIREDIS_SSL_H */ +#endif /* __HIREDICT_SSL_H */ diff --git a/hiredict_ssl.pc.in b/hiredict_ssl.pc.in index f7bdd99..cc47e77 100644 --- a/hiredict_ssl.pc.in +++ b/hiredict_ssl.pc.in @@ -3,11 +3,11 @@ install_libdir=@CMAKE_INSTALL_LIBDIR@ exec_prefix=${prefix} libdir=${exec_prefix}/${install_libdir} includedir=${prefix}/include -pkgincludedir=${includedir}/hiredis +pkgincludedir=${includedir}/hiredict -Name: hiredis_ssl -Description: SSL Support for hiredis. +Name: hiredict_ssl +Description: SSL Support for hiredict. Version: @PROJECT_VERSION@ -Requires: hiredis -Libs: -L${libdir} -lhiredis_ssl +Requires: hiredict +Libs: -L${libdir} -lhiredict_ssl Libs.private: -lssl -lcrypto diff --git a/net.c b/net.c index 9eac6bb..96cfa0e 100644 --- a/net.c +++ b/net.c @@ -1,4 +1,4 @@ -/* Extracted from anet.c to work properly with Hiredis error reporting. +/* Extracted from anet.c to work properly with Hiredict error reporting. * * Copyright (c) 2009-2011, Salvatore Sanfilippo * Copyright (c) 2010-2014, Pieter Noordhuis @@ -32,50 +32,50 @@ #include "sockcompat.h" #include "win32.h" -/* Defined in hiredis.c */ -void __redisSetError(redisContext *c, int type, const char *str); +/* Defined in hiredict.c */ +void __redictSetError(redictContext *c, int type, const char *str); -int redisContextUpdateCommandTimeout(redisContext *c, const struct timeval *timeout); +int redictContextUpdateCommandTimeout(redictContext *c, const struct timeval *timeout); -void redisNetClose(redisContext *c) { - if (c && c->fd != REDIS_INVALID_FD) { +void redictNetClose(redictContext *c) { + if (c && c->fd != REDICT_INVALID_FD) { close(c->fd); - c->fd = REDIS_INVALID_FD; + c->fd = REDICT_INVALID_FD; } } -ssize_t redisNetRead(redisContext *c, char *buf, size_t bufcap) { +ssize_t redictNetRead(redictContext *c, char *buf, size_t bufcap) { ssize_t nread = recv(c->fd, buf, bufcap, 0); if (nread == -1) { - if ((errno == EWOULDBLOCK && !(c->flags & REDIS_BLOCK)) || (errno == EINTR)) { + if ((errno == EWOULDBLOCK && !(c->flags & REDICT_BLOCK)) || (errno == EINTR)) { /* Try again later */ return 0; - } else if(errno == ETIMEDOUT && (c->flags & REDIS_BLOCK)) { + } else if(errno == ETIMEDOUT && (c->flags & REDICT_BLOCK)) { /* especially in windows */ - __redisSetError(c, REDIS_ERR_TIMEOUT, "recv timeout"); + __redictSetError(c, REDICT_ERR_TIMEOUT, "recv timeout"); return -1; } else { - __redisSetError(c, REDIS_ERR_IO, strerror(errno)); + __redictSetError(c, REDICT_ERR_IO, strerror(errno)); return -1; } } else if (nread == 0) { - __redisSetError(c, REDIS_ERR_EOF, "Server closed the connection"); + __redictSetError(c, REDICT_ERR_EOF, "Server closed the connection"); return -1; } else { return nread; } } -ssize_t redisNetWrite(redisContext *c) { +ssize_t redictNetWrite(redictContext *c) { ssize_t nwritten; nwritten = send(c->fd, c->obuf, sdslen(c->obuf), 0); if (nwritten < 0) { - if ((errno == EWOULDBLOCK && !(c->flags & REDIS_BLOCK)) || (errno == EINTR)) { + if ((errno == EWOULDBLOCK && !(c->flags & REDICT_BLOCK)) || (errno == EINTR)) { /* Try again */ return 0; } else { - __redisSetError(c, REDIS_ERR_IO, strerror(errno)); + __redictSetError(c, REDICT_ERR_IO, strerror(errno)); return -1; } } @@ -83,7 +83,7 @@ ssize_t redisNetWrite(redisContext *c) { return nwritten; } -static void __redisSetErrorFromErrno(redisContext *c, int type, const char *prefix) { +static void __redictSetErrorFromErrno(redictContext *c, int type, const char *prefix) { int errorno = errno; /* snprintf() may change errno */ char buf[128] = { 0 }; size_t len = 0; @@ -91,35 +91,35 @@ static void __redisSetErrorFromErrno(redisContext *c, int type, const char *pref if (prefix != NULL) len = snprintf(buf,sizeof(buf),"%s: ",prefix); strerror_r(errorno, (char *)(buf + len), sizeof(buf) - len); - __redisSetError(c,type,buf); + __redictSetError(c,type,buf); } -static int redisSetReuseAddr(redisContext *c) { +static int redictSetReuseAddr(redictContext *c) { int on = 1; if (setsockopt(c->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) { - __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL); - redisNetClose(c); - return REDIS_ERR; + __redictSetErrorFromErrno(c,REDICT_ERR_IO,NULL); + redictNetClose(c); + return REDICT_ERR; } - return REDIS_OK; + return REDICT_OK; } -static int redisCreateSocket(redisContext *c, int type) { - redisFD s; - if ((s = socket(type, SOCK_STREAM, 0)) == REDIS_INVALID_FD) { - __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL); - return REDIS_ERR; +static int redictCreateSocket(redictContext *c, int type) { + redictFD s; + if ((s = socket(type, SOCK_STREAM, 0)) == REDICT_INVALID_FD) { + __redictSetErrorFromErrno(c,REDICT_ERR_IO,NULL); + return REDICT_ERR; } c->fd = s; if (type == AF_INET) { - if (redisSetReuseAddr(c) == REDIS_ERR) { - return REDIS_ERR; + if (redictSetReuseAddr(c) == REDICT_ERR) { + return REDICT_ERR; } } - return REDIS_OK; + return REDICT_OK; } -static int redisSetBlocking(redisContext *c, int blocking) { +static int redictSetBlocking(redictContext *c, int blocking) { #ifndef _WIN32 int flags; @@ -127,9 +127,9 @@ static int redisSetBlocking(redisContext *c, int blocking) { * Note that fcntl(2) for F_GETFL and F_SETFL can't be * interrupted by a signal. */ if ((flags = fcntl(c->fd, F_GETFL)) == -1) { - __redisSetErrorFromErrno(c,REDIS_ERR_IO,"fcntl(F_GETFL)"); - redisNetClose(c); - return REDIS_ERR; + __redictSetErrorFromErrno(c,REDICT_ERR_IO,"fcntl(F_GETFL)"); + redictNetClose(c); + return REDICT_ERR; } if (blocking) @@ -138,86 +138,86 @@ static int redisSetBlocking(redisContext *c, int blocking) { flags |= O_NONBLOCK; if (fcntl(c->fd, F_SETFL, flags) == -1) { - __redisSetErrorFromErrno(c,REDIS_ERR_IO,"fcntl(F_SETFL)"); - redisNetClose(c); - return REDIS_ERR; + __redictSetErrorFromErrno(c,REDICT_ERR_IO,"fcntl(F_SETFL)"); + redictNetClose(c); + return REDICT_ERR; } #else u_long mode = blocking ? 0 : 1; if (ioctl(c->fd, FIONBIO, &mode) == -1) { - __redisSetErrorFromErrno(c, REDIS_ERR_IO, "ioctl(FIONBIO)"); - redisNetClose(c); - return REDIS_ERR; + __redictSetErrorFromErrno(c, REDICT_ERR_IO, "ioctl(FIONBIO)"); + redictNetClose(c); + return REDICT_ERR; } #endif /* _WIN32 */ - return REDIS_OK; + return REDICT_OK; } -int redisKeepAlive(redisContext *c, int interval) { +int redictKeepAlive(redictContext *c, int interval) { int val = 1; - redisFD fd = c->fd; + redictFD fd = c->fd; /* TCP_KEEPALIVE makes no sense with AF_UNIX connections */ - if (c->connection_type == REDIS_CONN_UNIX) - return REDIS_ERR; + if (c->connection_type == REDICT_CONN_UNIX) + return REDICT_ERR; #ifndef _WIN32 if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) == -1){ - __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); - return REDIS_ERR; + __redictSetError(c,REDICT_ERR_OTHER,strerror(errno)); + return REDICT_ERR; } val = interval; #if defined(__APPLE__) && defined(__MACH__) if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &val, sizeof(val)) < 0) { - __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); - return REDIS_ERR; + __redictSetError(c,REDICT_ERR_OTHER,strerror(errno)); + return REDICT_ERR; } #else #if defined(__GLIBC__) && !defined(__FreeBSD_kernel__) if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) { - __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); - return REDIS_ERR; + __redictSetError(c,REDICT_ERR_OTHER,strerror(errno)); + return REDICT_ERR; } val = interval/3; if (val == 0) val = 1; if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof(val)) < 0) { - __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); - return REDIS_ERR; + __redictSetError(c,REDICT_ERR_OTHER,strerror(errno)); + return REDICT_ERR; } val = 3; if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &val, sizeof(val)) < 0) { - __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); - return REDIS_ERR; + __redictSetError(c,REDICT_ERR_OTHER,strerror(errno)); + return REDICT_ERR; } #endif #endif #else int res; - res = win32_redisKeepAlive(fd, interval * 1000); + res = win32_redictKeepAlive(fd, interval * 1000); if (res != 0) { - __redisSetError(c, REDIS_ERR_OTHER, strerror(res)); - return REDIS_ERR; + __redictSetError(c, REDICT_ERR_OTHER, strerror(res)); + return REDICT_ERR; } #endif - return REDIS_OK; + return REDICT_OK; } -int redisSetTcpNoDelay(redisContext *c) { +int redictSetTcpNoDelay(redictContext *c) { int yes = 1; if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)) == -1) { - __redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(TCP_NODELAY)"); - redisNetClose(c); - return REDIS_ERR; + __redictSetErrorFromErrno(c,REDICT_ERR_IO,"setsockopt(TCP_NODELAY)"); + redictNetClose(c); + return REDICT_ERR; } - return REDIS_OK; + return REDICT_OK; } -int redisContextSetTcpUserTimeout(redisContext *c, unsigned int timeout) { +int redictContextSetTcpUserTimeout(redictContext *c, unsigned int timeout) { int res; #ifdef TCP_USER_TIMEOUT res = setsockopt(c->fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout, sizeof(timeout)); @@ -227,16 +227,16 @@ int redisContextSetTcpUserTimeout(redisContext *c, unsigned int timeout) { (void)timeout; #endif if (res == -1) { - __redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(TCP_USER_TIMEOUT)"); - redisNetClose(c); - return REDIS_ERR; + __redictSetErrorFromErrno(c,REDICT_ERR_IO,"setsockopt(TCP_USER_TIMEOUT)"); + redictNetClose(c); + return REDICT_ERR; } - return REDIS_OK; + return REDICT_OK; } #define __MAX_MSEC (((LONG_MAX) - 999) / 1000) -static int redisContextTimeoutMsec(redisContext *c, long *result) +static int redictContextTimeoutMsec(redictContext *c, long *result) { const struct timeval *timeout = c->connect_timeout; long msec = -1; @@ -244,9 +244,9 @@ static int redisContextTimeoutMsec(redisContext *c, long *result) /* Only use timeout when not NULL. */ if (timeout != NULL) { if (timeout->tv_usec > 1000000 || timeout->tv_sec > __MAX_MSEC) { - __redisSetError(c, REDIS_ERR_IO, "Invalid timeout specified"); + __redictSetError(c, REDICT_ERR_IO, "Invalid timeout specified"); *result = msec; - return REDIS_ERR; + return REDICT_ERR; } msec = (timeout->tv_sec * 1000) + ((timeout->tv_usec + 999) / 1000); @@ -257,10 +257,10 @@ static int redisContextTimeoutMsec(redisContext *c, long *result) } *result = msec; - return REDIS_OK; + return REDICT_OK; } -static long redisPollMillis(void) { +static long redictPollMillis(void) { #ifndef _MSC_VER struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); @@ -272,49 +272,49 @@ static long redisPollMillis(void) { #endif } -static int redisContextWaitReady(redisContext *c, long msec) { +static int redictContextWaitReady(redictContext *c, long msec) { struct pollfd wfd; long end; int res; if (errno != EINPROGRESS) { - __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL); - redisNetClose(c); - return REDIS_ERR; + __redictSetErrorFromErrno(c,REDICT_ERR_IO,NULL); + redictNetClose(c); + return REDICT_ERR; } wfd.fd = c->fd; wfd.events = POLLOUT; - end = msec >= 0 ? redisPollMillis() + msec : 0; + end = msec >= 0 ? redictPollMillis() + msec : 0; while ((res = poll(&wfd, 1, msec)) <= 0) { if (res < 0 && errno != EINTR) { - __redisSetErrorFromErrno(c, REDIS_ERR_IO, "poll(2)"); - redisNetClose(c); - return REDIS_ERR; - } else if (res == 0 || (msec >= 0 && redisPollMillis() >= end)) { + __redictSetErrorFromErrno(c, REDICT_ERR_IO, "poll(2)"); + redictNetClose(c); + return REDICT_ERR; + } else if (res == 0 || (msec >= 0 && redictPollMillis() >= end)) { errno = ETIMEDOUT; - __redisSetErrorFromErrno(c, REDIS_ERR_IO, NULL); - redisNetClose(c); - return REDIS_ERR; + __redictSetErrorFromErrno(c, REDICT_ERR_IO, NULL); + redictNetClose(c); + return REDICT_ERR; } else { /* res < 0 && errno == EINTR, try again */ } } - if (redisCheckConnectDone(c, &res) != REDIS_OK || res == 0) { - redisCheckSocketError(c); - return REDIS_ERR; + if (redictCheckConnectDone(c, &res) != REDICT_OK || res == 0) { + redictCheckSocketError(c); + return REDICT_ERR; } - return REDIS_OK; + return REDICT_OK; } -int redisCheckConnectDone(redisContext *c, int *completed) { +int redictCheckConnectDone(redictContext *c, int *completed) { int rc = connect(c->fd, (const struct sockaddr *)c->saddr, c->addrlen); if (rc == 0) { *completed = 1; - return REDIS_OK; + return REDICT_OK; } int error = errno; if (error == EINPROGRESS) { @@ -326,7 +326,7 @@ int redisCheckConnectDone(redisContext *c, int *completed) { if (so_error == 0) { /* Socket is connected! */ *completed = 1; - return REDIS_OK; + return REDICT_OK; } /* connection error; */ errno = so_error; @@ -336,23 +336,23 @@ int redisCheckConnectDone(redisContext *c, int *completed) { switch (error) { case EISCONN: *completed = 1; - return REDIS_OK; + return REDICT_OK; case EALREADY: case EWOULDBLOCK: *completed = 0; - return REDIS_OK; + return REDICT_OK; default: - return REDIS_ERR; + return REDICT_ERR; } } -int redisCheckSocketError(redisContext *c) { +int redictCheckSocketError(redictContext *c) { int err = 0, errno_saved = errno; socklen_t errlen = sizeof(err); if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, &err, &errlen) == -1) { - __redisSetErrorFromErrno(c,REDIS_ERR_IO,"getsockopt(SO_ERROR)"); - return REDIS_ERR; + __redictSetErrorFromErrno(c,REDICT_ERR_IO,"getsockopt(SO_ERROR)"); + return REDICT_ERR; } if (err == 0) { @@ -361,78 +361,78 @@ int redisCheckSocketError(redisContext *c) { if (err) { errno = err; - __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL); - return REDIS_ERR; + __redictSetErrorFromErrno(c,REDICT_ERR_IO,NULL); + return REDICT_ERR; } - return REDIS_OK; + return REDICT_OK; } -int redisContextSetTimeout(redisContext *c, const struct timeval tv) { +int redictContextSetTimeout(redictContext *c, const struct timeval tv) { const void *to_ptr = &tv; size_t to_sz = sizeof(tv); - if (redisContextUpdateCommandTimeout(c, &tv) != REDIS_OK) { - __redisSetError(c, REDIS_ERR_OOM, "Out of memory"); - return REDIS_ERR; + if (redictContextUpdateCommandTimeout(c, &tv) != REDICT_OK) { + __redictSetError(c, REDICT_ERR_OOM, "Out of memory"); + return REDICT_ERR; } if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,to_ptr,to_sz) == -1) { - __redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_RCVTIMEO)"); - return REDIS_ERR; + __redictSetErrorFromErrno(c,REDICT_ERR_IO,"setsockopt(SO_RCVTIMEO)"); + return REDICT_ERR; } if (setsockopt(c->fd,SOL_SOCKET,SO_SNDTIMEO,to_ptr,to_sz) == -1) { - __redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_SNDTIMEO)"); - return REDIS_ERR; + __redictSetErrorFromErrno(c,REDICT_ERR_IO,"setsockopt(SO_SNDTIMEO)"); + return REDICT_ERR; } - return REDIS_OK; + return REDICT_OK; } -int redisContextUpdateConnectTimeout(redisContext *c, const struct timeval *timeout) { +int redictContextUpdateConnectTimeout(redictContext *c, const struct timeval *timeout) { /* Same timeval struct, short circuit */ if (c->connect_timeout == timeout) - return REDIS_OK; + return REDICT_OK; /* Allocate context timeval if we need to */ if (c->connect_timeout == NULL) { c->connect_timeout = hi_malloc(sizeof(*c->connect_timeout)); if (c->connect_timeout == NULL) - return REDIS_ERR; + return REDICT_ERR; } memcpy(c->connect_timeout, timeout, sizeof(*c->connect_timeout)); - return REDIS_OK; + return REDICT_OK; } -int redisContextUpdateCommandTimeout(redisContext *c, const struct timeval *timeout) { +int redictContextUpdateCommandTimeout(redictContext *c, const struct timeval *timeout) { /* Same timeval struct, short circuit */ if (c->command_timeout == timeout) - return REDIS_OK; + return REDICT_OK; /* Allocate context timeval if we need to */ if (c->command_timeout == NULL) { c->command_timeout = hi_malloc(sizeof(*c->command_timeout)); if (c->command_timeout == NULL) - return REDIS_ERR; + return REDICT_ERR; } memcpy(c->command_timeout, timeout, sizeof(*c->command_timeout)); - return REDIS_OK; + return REDICT_OK; } -static int _redisContextConnectTcp(redisContext *c, const char *addr, int port, +static int _redictContextConnectTcp(redictContext *c, const char *addr, int port, const struct timeval *timeout, const char *source_addr) { - redisFD s; + redictFD s; int rv, n; char _port[6]; /* strlen("65535"); */ struct addrinfo hints, *servinfo, *bservinfo, *p, *b; - int blocking = (c->flags & REDIS_BLOCK); - int reuseaddr = (c->flags & REDIS_REUSEADDR); + int blocking = (c->flags & REDICT_BLOCK); + int reuseaddr = (c->flags & REDICT_REUSEADDR); int reuses = 0; long timeout_msec = -1; servinfo = NULL; - c->connection_type = REDIS_CONN_TCP; + c->connection_type = REDICT_CONN_TCP; c->tcp.port = port; /* We need to take possession of the passed parameters @@ -451,14 +451,14 @@ static int _redisContextConnectTcp(redisContext *c, const char *addr, int port, } if (timeout) { - if (redisContextUpdateConnectTimeout(c, timeout) == REDIS_ERR) + if (redictContextUpdateConnectTimeout(c, timeout) == REDICT_ERR) goto oom; } else { hi_free(c->connect_timeout); c->connect_timeout = NULL; } - if (redisContextTimeoutMsec(c, &timeout_msec) != REDIS_OK) { + if (redictContextTimeoutMsec(c, &timeout_msec) != REDICT_OK) { goto error; } @@ -478,9 +478,9 @@ static int _redisContextConnectTcp(redisContext *c, const char *addr, int port, /* DNS lookup. To use dual stack, set both flags to prefer both IPv4 and * IPv6. By default, for historical reasons, we try IPv4 first and then we * try IPv6 only if no IPv4 address was found. */ - if (c->flags & REDIS_PREFER_IPV6 && c->flags & REDIS_PREFER_IPV4) + if (c->flags & REDICT_PREFER_IPV6 && c->flags & REDICT_PREFER_IPV4) hints.ai_family = AF_UNSPEC; - else if (c->flags & REDIS_PREFER_IPV6) + else if (c->flags & REDICT_PREFER_IPV6) hints.ai_family = AF_INET6; else hints.ai_family = AF_INET; @@ -492,16 +492,16 @@ static int _redisContextConnectTcp(redisContext *c, const char *addr, int port, rv = getaddrinfo(c->tcp.host, _port, &hints, &servinfo); } if (rv != 0) { - __redisSetError(c, REDIS_ERR_OTHER, gai_strerror(rv)); - return REDIS_ERR; + __redictSetError(c, REDICT_ERR_OTHER, gai_strerror(rv)); + return REDICT_ERR; } for (p = servinfo; p != NULL; p = p->ai_next) { addrretry: - if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == REDIS_INVALID_FD) + if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == REDICT_INVALID_FD) continue; c->fd = s; - if (redisSetBlocking(c,0) != REDIS_OK) + if (redictSetBlocking(c,0) != REDICT_OK) goto error; if (c->tcp.source_addr) { int bound = 0; @@ -509,7 +509,7 @@ addrretry: if ((rv = getaddrinfo(c->tcp.source_addr, NULL, &hints, &bservinfo)) != 0) { char buf[128]; snprintf(buf,sizeof(buf),"Can't get addr: %s",gai_strerror(rv)); - __redisSetError(c,REDIS_ERR_OTHER,buf); + __redictSetError(c,REDICT_ERR_OTHER,buf); goto error; } @@ -532,7 +532,7 @@ addrretry: if (!bound) { char buf[128]; snprintf(buf,sizeof(buf),"Can't bind socket: %s",strerror(errno)); - __redisSetError(c,REDIS_ERR_OTHER,buf); + __redictSetError(c,REDICT_ERR_OTHER,buf); goto error; } } @@ -548,7 +548,7 @@ addrretry: if (connect(s,p->ai_addr,p->ai_addrlen) == -1) { if (errno == EHOSTUNREACH) { - redisNetClose(c); + redictNetClose(c); continue; } else if (errno == EINPROGRESS) { if (blocking) { @@ -559,69 +559,69 @@ addrretry: * for `connect()` */ } else if (errno == EADDRNOTAVAIL && reuseaddr) { - if (++reuses >= REDIS_CONNECT_RETRIES) { + if (++reuses >= REDICT_CONNECT_RETRIES) { goto error; } else { - redisNetClose(c); + redictNetClose(c); goto addrretry; } } else { wait_for_ready: - if (redisContextWaitReady(c,timeout_msec) != REDIS_OK) + if (redictContextWaitReady(c,timeout_msec) != REDICT_OK) goto error; - if (redisSetTcpNoDelay(c) != REDIS_OK) + if (redictSetTcpNoDelay(c) != REDICT_OK) goto error; } } - if (blocking && redisSetBlocking(c,1) != REDIS_OK) + if (blocking && redictSetBlocking(c,1) != REDICT_OK) goto error; - c->flags |= REDIS_CONNECTED; - rv = REDIS_OK; + c->flags |= REDICT_CONNECTED; + rv = REDICT_OK; goto end; } if (p == NULL) { char buf[128]; snprintf(buf,sizeof(buf),"Can't create socket: %s",strerror(errno)); - __redisSetError(c,REDIS_ERR_OTHER,buf); + __redictSetError(c,REDICT_ERR_OTHER,buf); goto error; } oom: - __redisSetError(c, REDIS_ERR_OOM, "Out of memory"); + __redictSetError(c, REDICT_ERR_OOM, "Out of memory"); error: - rv = REDIS_ERR; + rv = REDICT_ERR; end: if(servinfo) { freeaddrinfo(servinfo); } - return rv; // Need to return REDIS_OK if alright + return rv; // Need to return REDICT_OK if alright } -int redisContextConnectTcp(redisContext *c, const char *addr, int port, +int redictContextConnectTcp(redictContext *c, const char *addr, int port, const struct timeval *timeout) { - return _redisContextConnectTcp(c, addr, port, timeout, NULL); + return _redictContextConnectTcp(c, addr, port, timeout, NULL); } -int redisContextConnectBindTcp(redisContext *c, const char *addr, int port, +int redictContextConnectBindTcp(redictContext *c, const char *addr, int port, const struct timeval *timeout, const char *source_addr) { - return _redisContextConnectTcp(c, addr, port, timeout, source_addr); + return _redictContextConnectTcp(c, addr, port, timeout, source_addr); } -int redisContextConnectUnix(redisContext *c, const char *path, const struct timeval *timeout) { +int redictContextConnectUnix(redictContext *c, const char *path, const struct timeval *timeout) { #ifndef _WIN32 - int blocking = (c->flags & REDIS_BLOCK); + int blocking = (c->flags & REDICT_BLOCK); struct sockaddr_un *sa; long timeout_msec = -1; - if (redisCreateSocket(c,AF_UNIX) < 0) - return REDIS_ERR; - if (redisSetBlocking(c,0) != REDIS_OK) - return REDIS_ERR; + if (redictCreateSocket(c,AF_UNIX) < 0) + return REDICT_ERR; + if (redictSetBlocking(c,0) != REDICT_OK) + return REDICT_ERR; - c->connection_type = REDIS_CONN_UNIX; + c->connection_type = REDICT_CONN_UNIX; if (c->unix_sock.path != path) { hi_free(c->unix_sock.path); @@ -631,15 +631,15 @@ int redisContextConnectUnix(redisContext *c, const char *path, const struct time } if (timeout) { - if (redisContextUpdateConnectTimeout(c, timeout) == REDIS_ERR) + if (redictContextUpdateConnectTimeout(c, timeout) == REDICT_ERR) goto oom; } else { hi_free(c->connect_timeout); c->connect_timeout = NULL; } - if (redisContextTimeoutMsec(c,&timeout_msec) != REDIS_OK) - return REDIS_ERR; + if (redictContextTimeoutMsec(c,&timeout_msec) != REDICT_OK) + return REDICT_ERR; /* Don't leak sockaddr if we're reconnecting */ if (c->saddr) hi_free(c->saddr); @@ -655,24 +655,24 @@ int redisContextConnectUnix(redisContext *c, const char *path, const struct time if (errno == EINPROGRESS && !blocking) { /* This is ok. */ } else { - if (redisContextWaitReady(c,timeout_msec) != REDIS_OK) - return REDIS_ERR; + if (redictContextWaitReady(c,timeout_msec) != REDICT_OK) + return REDICT_ERR; } } /* Reset socket to be blocking after connect(2). */ - if (blocking && redisSetBlocking(c,1) != REDIS_OK) - return REDIS_ERR; + if (blocking && redictSetBlocking(c,1) != REDICT_OK) + return REDICT_ERR; - c->flags |= REDIS_CONNECTED; - return REDIS_OK; + c->flags |= REDICT_CONNECTED; + return REDICT_OK; #else /* We currently do not support Unix sockets for Windows. */ /* TODO(m): https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/ */ errno = EPROTONOSUPPORT; - return REDIS_ERR; + return REDICT_ERR; #endif /* _WIN32 */ oom: - __redisSetError(c, REDIS_ERR_OOM, "Out of memory"); - return REDIS_ERR; + __redictSetError(c, REDICT_ERR_OOM, "Out of memory"); + return REDICT_ERR; } diff --git a/net.h b/net.h index d9bc357..be66e19 100644 --- a/net.h +++ b/net.h @@ -1,4 +1,4 @@ -/* Extracted from anet.c to work properly with Hiredis error reporting. +/* Extracted from anet.c to work properly with Hiredict error reporting. * * Copyright (c) 2009-2011, Salvatore Sanfilippo * Copyright (c) 2010-2014, Pieter Noordhuis @@ -21,21 +21,21 @@ #include "hiredict.h" -void redisNetClose(redisContext *c); -ssize_t redisNetRead(redisContext *c, char *buf, size_t bufcap); -ssize_t redisNetWrite(redisContext *c); +void redictNetClose(redictContext *c); +ssize_t redictNetRead(redictContext *c, char *buf, size_t bufcap); +ssize_t redictNetWrite(redictContext *c); -int redisCheckSocketError(redisContext *c); -int redisContextSetTimeout(redisContext *c, const struct timeval tv); -int redisContextConnectTcp(redisContext *c, const char *addr, int port, const struct timeval *timeout); -int redisContextConnectBindTcp(redisContext *c, const char *addr, int port, +int redictCheckSocketError(redictContext *c); +int redictContextSetTimeout(redictContext *c, const struct timeval tv); +int redictContextConnectTcp(redictContext *c, const char *addr, int port, const struct timeval *timeout); +int redictContextConnectBindTcp(redictContext *c, const char *addr, int port, const struct timeval *timeout, const char *source_addr); -int redisContextConnectUnix(redisContext *c, const char *path, const struct timeval *timeout); -int redisKeepAlive(redisContext *c, int interval); -int redisCheckConnectDone(redisContext *c, int *completed); +int redictContextConnectUnix(redictContext *c, const char *path, const struct timeval *timeout); +int redictKeepAlive(redictContext *c, int interval); +int redictCheckConnectDone(redictContext *c, int *completed); -int redisSetTcpNoDelay(redisContext *c); -int redisContextSetTcpUserTimeout(redisContext *c, unsigned int timeout); +int redictSetTcpNoDelay(redictContext *c); +int redictContextSetTcpUserTimeout(redictContext *c, unsigned int timeout); #endif diff --git a/read.c b/read.c index 55060b4..7b50ff2 100644 --- a/read.c +++ b/read.c @@ -30,9 +30,9 @@ #include "win32.h" /* Initial size of our nested reply stack and how much we grow it when needd */ -#define REDIS_READER_STACK_SIZE 9 +#define REDICT_READER_STACK_SIZE 9 -static void __redisReaderSetError(redisReader *r, int type, const char *str) { +static void __redictReaderSetError(redictReader *r, int type, const char *str) { size_t len; if (r->reply != NULL && r->fn && r->fn->freeObject) { @@ -80,20 +80,20 @@ static size_t chrtos(char *buf, size_t size, char byte) { return len; } -static void __redisReaderSetErrorProtocolByte(redisReader *r, char byte) { +static void __redictReaderSetErrorProtocolByte(redictReader *r, char byte) { char cbuf[8], sbuf[128]; chrtos(cbuf,sizeof(cbuf),byte); snprintf(sbuf,sizeof(sbuf), "Protocol error, got %s as reply type byte", cbuf); - __redisReaderSetError(r,REDIS_ERR_PROTOCOL,sbuf); + __redictReaderSetError(r,REDICT_ERR_PROTOCOL,sbuf); } -static void __redisReaderSetErrorOOM(redisReader *r) { - __redisReaderSetError(r,REDIS_ERR_OOM,"Out of memory"); +static void __redictReaderSetErrorOOM(redictReader *r) { + __redictReaderSetError(r,REDICT_ERR_OOM,"Out of memory"); } -static char *readBytes(redisReader *r, unsigned int bytes) { +static char *readBytes(redictReader *r, unsigned int bytes) { char *p; if (r->len-r->pos >= bytes) { p = r->buf+r->pos; @@ -129,8 +129,8 @@ static char *seekNewline(char *s, size_t len) { return ret; } -/* Convert a string into a long long. Returns REDIS_OK if the string could be - * parsed into a (non-overflowing) long long, REDIS_ERR otherwise. The value +/* Convert a string into a long long. Returns REDICT_OK if the string could be + * parsed into a (non-overflowing) long long, REDICT_ERR otherwise. The value * will be set to the parsed value when appropriate. * * Note that this function demands that the string strictly represents @@ -148,12 +148,12 @@ static int string2ll(const char *s, size_t slen, long long *value) { unsigned long long v; if (plen == slen) - return REDIS_ERR; + return REDICT_ERR; /* Special case: first and only digit is 0. */ if (slen == 1 && p[0] == '0') { if (value != NULL) *value = 0; - return REDIS_OK; + return REDICT_OK; } if (p[0] == '-') { @@ -162,7 +162,7 @@ static int string2ll(const char *s, size_t slen, long long *value) { /* Abort on only a negative sign. */ if (plen == slen) - return REDIS_ERR; + return REDICT_ERR; } /* First digit should be 1-9, otherwise the string should just be 0. */ @@ -171,18 +171,18 @@ static int string2ll(const char *s, size_t slen, long long *value) { p++; plen++; } else if (p[0] == '0' && slen == 1) { *value = 0; - return REDIS_OK; + return REDICT_OK; } else { - return REDIS_ERR; + return REDICT_ERR; } while (plen < slen && p[0] >= '0' && p[0] <= '9') { if (v > (ULLONG_MAX / 10)) /* Overflow. */ - return REDIS_ERR; + return REDICT_ERR; v *= 10; if (v > (ULLONG_MAX - (p[0]-'0'))) /* Overflow. */ - return REDIS_ERR; + return REDICT_ERR; v += p[0]-'0'; p++; plen++; @@ -190,21 +190,21 @@ static int string2ll(const char *s, size_t slen, long long *value) { /* Return if not all bytes were used. */ if (plen < slen) - return REDIS_ERR; + return REDICT_ERR; if (negative) { if (v > ((unsigned long long)(-(LLONG_MIN+1))+1)) /* Overflow. */ - return REDIS_ERR; + return REDICT_ERR; if (value != NULL) *value = -v; } else { if (v > LLONG_MAX) /* Overflow. */ - return REDIS_ERR; + return REDICT_ERR; if (value != NULL) *value = v; } - return REDIS_OK; + return REDICT_OK; } -static char *readLine(redisReader *r, int *_len) { +static char *readLine(redictReader *r, int *_len) { char *p, *s; int len; @@ -219,8 +219,8 @@ static char *readLine(redisReader *r, int *_len) { return NULL; } -static void moveToNextTask(redisReader *r) { - redisReadTask *cur, *prv; +static void moveToNextTask(redictReader *r) { + redictReadTask *cur, *prv; while (r->ridx >= 0) { /* Return a.s.a.p. when the stack is now empty. */ if (r->ridx == 0) { @@ -230,11 +230,11 @@ static void moveToNextTask(redisReader *r) { cur = r->task[r->ridx]; prv = r->task[r->ridx-1]; - assert(prv->type == REDIS_REPLY_ARRAY || - prv->type == REDIS_REPLY_MAP || - prv->type == REDIS_REPLY_ATTR || - prv->type == REDIS_REPLY_SET || - prv->type == REDIS_REPLY_PUSH); + assert(prv->type == REDICT_REPLY_ARRAY || + prv->type == REDICT_REPLY_MAP || + prv->type == REDICT_REPLY_ATTR || + prv->type == REDICT_REPLY_SET || + prv->type == REDICT_REPLY_PUSH); if (cur->idx == prv->elements-1) { r->ridx--; } else { @@ -248,35 +248,35 @@ static void moveToNextTask(redisReader *r) { } } -static int processLineItem(redisReader *r) { - redisReadTask *cur = r->task[r->ridx]; +static int processLineItem(redictReader *r) { + redictReadTask *cur = r->task[r->ridx]; void *obj; char *p; int len; if ((p = readLine(r,&len)) != NULL) { - if (cur->type == REDIS_REPLY_INTEGER) { + if (cur->type == REDICT_REPLY_INTEGER) { long long v; - if (string2ll(p, len, &v) == REDIS_ERR) { - __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + if (string2ll(p, len, &v) == REDICT_ERR) { + __redictReaderSetError(r,REDICT_ERR_PROTOCOL, "Bad integer value"); - return REDIS_ERR; + return REDICT_ERR; } if (r->fn && r->fn->createInteger) { obj = r->fn->createInteger(cur,v); } else { - obj = (void*)REDIS_REPLY_INTEGER; + obj = (void*)REDICT_REPLY_INTEGER; } - } else if (cur->type == REDIS_REPLY_DOUBLE) { + } else if (cur->type == REDICT_REPLY_DOUBLE) { char buf[326], *eptr; double d; if ((size_t)len >= sizeof(buf)) { - __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + __redictReaderSetError(r,REDICT_ERR_PROTOCOL, "Double value is too large"); - return REDIS_ERR; + return REDICT_ERR; } memcpy(buf,p,len); @@ -296,65 +296,65 @@ static int processLineItem(redisReader *r) { * etc. We explicity handle our two allowed infinite cases and NaN * above, so strtod() should only result in finite values. */ if (buf[0] == '\0' || eptr != &buf[len] || !isfinite(d)) { - __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + __redictReaderSetError(r,REDICT_ERR_PROTOCOL, "Bad double value"); - return REDIS_ERR; + return REDICT_ERR; } } if (r->fn && r->fn->createDouble) { obj = r->fn->createDouble(cur,d,buf,len); } else { - obj = (void*)REDIS_REPLY_DOUBLE; + obj = (void*)REDICT_REPLY_DOUBLE; } - } else if (cur->type == REDIS_REPLY_NIL) { + } else if (cur->type == REDICT_REPLY_NIL) { if (len != 0) { - __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + __redictReaderSetError(r,REDICT_ERR_PROTOCOL, "Bad nil value"); - return REDIS_ERR; + return REDICT_ERR; } if (r->fn && r->fn->createNil) obj = r->fn->createNil(cur); else - obj = (void*)REDIS_REPLY_NIL; - } else if (cur->type == REDIS_REPLY_BOOL) { + obj = (void*)REDICT_REPLY_NIL; + } else if (cur->type == REDICT_REPLY_BOOL) { int bval; if (len != 1 || !strchr("tTfF", p[0])) { - __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + __redictReaderSetError(r,REDICT_ERR_PROTOCOL, "Bad bool value"); - return REDIS_ERR; + return REDICT_ERR; } bval = p[0] == 't' || p[0] == 'T'; if (r->fn && r->fn->createBool) obj = r->fn->createBool(cur,bval); else - obj = (void*)REDIS_REPLY_BOOL; - } else if (cur->type == REDIS_REPLY_BIGNUM) { + obj = (void*)REDICT_REPLY_BOOL; + } else if (cur->type == REDICT_REPLY_BIGNUM) { /* Ensure all characters are decimal digits (with possible leading * minus sign). */ for (int i = 0; i < len; i++) { /* XXX Consider: Allow leading '+'? Error on leading '0's? */ if (i == 0 && p[0] == '-') continue; if (p[i] < '0' || p[i] > '9') { - __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + __redictReaderSetError(r,REDICT_ERR_PROTOCOL, "Bad bignum value"); - return REDIS_ERR; + return REDICT_ERR; } } if (r->fn && r->fn->createString) obj = r->fn->createString(cur,p,len); else - obj = (void*)REDIS_REPLY_BIGNUM; + obj = (void*)REDICT_REPLY_BIGNUM; } else { /* Type will be error or status. */ for (int i = 0; i < len; i++) { if (p[i] == '\r' || p[i] == '\n') { - __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + __redictReaderSetError(r,REDICT_ERR_PROTOCOL, "Bad simple string value"); - return REDIS_ERR; + return REDICT_ERR; } } if (r->fn && r->fn->createString) @@ -364,21 +364,21 @@ static int processLineItem(redisReader *r) { } if (obj == NULL) { - __redisReaderSetErrorOOM(r); - return REDIS_ERR; + __redictReaderSetErrorOOM(r); + return REDICT_ERR; } /* Set reply if this is the root object. */ if (r->ridx == 0) r->reply = obj; moveToNextTask(r); - return REDIS_OK; + return REDICT_OK; } - return REDIS_ERR; + return REDICT_ERR; } -static int processBulkItem(redisReader *r) { - redisReadTask *cur = r->task[r->ridx]; +static int processBulkItem(redictReader *r) { + redictReadTask *cur = r->task[r->ridx]; void *obj = NULL; char *p, *s; long long len; @@ -391,16 +391,16 @@ static int processBulkItem(redisReader *r) { p = r->buf+r->pos; bytelen = s-(r->buf+r->pos)+2; /* include \r\n */ - if (string2ll(p, bytelen - 2, &len) == REDIS_ERR) { - __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + if (string2ll(p, bytelen - 2, &len) == REDICT_ERR) { + __redictReaderSetError(r,REDICT_ERR_PROTOCOL, "Bad bulk string length"); - return REDIS_ERR; + return REDICT_ERR; } if (len < -1 || (LLONG_MAX > SIZE_MAX && len > (long long)SIZE_MAX)) { - __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + __redictReaderSetError(r,REDICT_ERR_PROTOCOL, "Bulk string length out of range"); - return REDIS_ERR; + return REDICT_ERR; } if (len == -1) { @@ -408,19 +408,19 @@ static int processBulkItem(redisReader *r) { if (r->fn && r->fn->createNil) obj = r->fn->createNil(cur); else - obj = (void*)REDIS_REPLY_NIL; + obj = (void*)REDICT_REPLY_NIL; success = 1; } else { /* Only continue when the buffer contains the entire bulk item. */ bytelen += len+2; /* include \r\n */ if (r->pos+bytelen <= r->len) { - if ((cur->type == REDIS_REPLY_VERB && len < 4) || - (cur->type == REDIS_REPLY_VERB && s[5] != ':')) + if ((cur->type == REDICT_REPLY_VERB && len < 4) || + (cur->type == REDICT_REPLY_VERB && s[5] != ':')) { - __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + __redictReaderSetError(r,REDICT_ERR_PROTOCOL, "Verbatim string 4 bytes of content type are " "missing or incorrectly encoded."); - return REDIS_ERR; + return REDICT_ERR; } if (r->fn && r->fn->createString) obj = r->fn->createString(cur,s+2,len); @@ -433,8 +433,8 @@ static int processBulkItem(redisReader *r) { /* Proceed when obj was created. */ if (success) { if (obj == NULL) { - __redisReaderSetErrorOOM(r); - return REDIS_ERR; + __redictReaderSetErrorOOM(r); + return REDICT_ERR; } r->pos += bytelen; @@ -442,19 +442,19 @@ static int processBulkItem(redisReader *r) { /* Set reply if this is the root object. */ if (r->ridx == 0) r->reply = obj; moveToNextTask(r); - return REDIS_OK; + return REDICT_OK; } } - return REDIS_ERR; + return REDICT_ERR; } -static int redisReaderGrow(redisReader *r) { - redisReadTask **aux; +static int redictReaderGrow(redictReader *r) { + redictReadTask **aux; int newlen; /* Grow our stack size */ - newlen = r->tasks + REDIS_READER_STACK_SIZE; + newlen = r->tasks + REDICT_READER_STACK_SIZE; aux = hi_realloc(r->task, sizeof(*r->task) * newlen); if (aux == NULL) goto oom; @@ -468,30 +468,30 @@ static int redisReaderGrow(redisReader *r) { goto oom; } - return REDIS_OK; + return REDICT_OK; oom: - __redisReaderSetErrorOOM(r); - return REDIS_ERR; + __redictReaderSetErrorOOM(r); + return REDICT_ERR; } /* Process the array, map and set types. */ -static int processAggregateItem(redisReader *r) { - redisReadTask *cur = r->task[r->ridx]; +static int processAggregateItem(redictReader *r) { + redictReadTask *cur = r->task[r->ridx]; void *obj; char *p; long long elements; int root = 0, len; if (r->ridx == r->tasks - 1) { - if (redisReaderGrow(r) == REDIS_ERR) - return REDIS_ERR; + if (redictReaderGrow(r) == REDICT_ERR) + return REDICT_ERR; } if ((p = readLine(r,&len)) != NULL) { - if (string2ll(p, len, &elements) == REDIS_ERR) { - __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + if (string2ll(p, len, &elements) == REDICT_ERR) { + __redictReaderSetError(r,REDICT_ERR_PROTOCOL, "Bad multi-bulk length"); - return REDIS_ERR; + return REDICT_ERR; } root = (r->ridx == 0); @@ -499,25 +499,25 @@ static int processAggregateItem(redisReader *r) { if (elements < -1 || (LLONG_MAX > SIZE_MAX && elements > SIZE_MAX) || (r->maxelements > 0 && elements > r->maxelements)) { - __redisReaderSetError(r,REDIS_ERR_PROTOCOL, + __redictReaderSetError(r,REDICT_ERR_PROTOCOL, "Multi-bulk length out of range"); - return REDIS_ERR; + return REDICT_ERR; } if (elements == -1) { if (r->fn && r->fn->createNil) obj = r->fn->createNil(cur); else - obj = (void*)REDIS_REPLY_NIL; + obj = (void*)REDICT_REPLY_NIL; if (obj == NULL) { - __redisReaderSetErrorOOM(r); - return REDIS_ERR; + __redictReaderSetErrorOOM(r); + return REDICT_ERR; } moveToNextTask(r); } else { - if (cur->type == REDIS_REPLY_MAP || cur->type == REDIS_REPLY_ATTR) elements *= 2; + if (cur->type == REDICT_REPLY_MAP || cur->type == REDICT_REPLY_ATTR) elements *= 2; if (r->fn && r->fn->createArray) obj = r->fn->createArray(cur,elements); @@ -525,8 +525,8 @@ static int processAggregateItem(redisReader *r) { obj = (void*)(uintptr_t)cur->type; if (obj == NULL) { - __redisReaderSetErrorOOM(r); - return REDIS_ERR; + __redictReaderSetErrorOOM(r); + return REDICT_ERR; } /* Modify task stack when there are more than 0 elements. */ @@ -547,14 +547,14 @@ static int processAggregateItem(redisReader *r) { /* Set reply if this is the root object. */ if (root) r->reply = obj; - return REDIS_OK; + return REDICT_OK; } - return REDIS_ERR; + return REDICT_ERR; } -static int processItem(redisReader *r) { - redisReadTask *cur = r->task[r->ridx]; +static int processItem(redictReader *r) { + redictReadTask *cur = r->task[r->ridx]; char *p; /* check if we need to read type */ @@ -562,86 +562,86 @@ static int processItem(redisReader *r) { if ((p = readBytes(r,1)) != NULL) { switch (p[0]) { case '-': - cur->type = REDIS_REPLY_ERROR; + cur->type = REDICT_REPLY_ERROR; break; case '+': - cur->type = REDIS_REPLY_STATUS; + cur->type = REDICT_REPLY_STATUS; break; case ':': - cur->type = REDIS_REPLY_INTEGER; + cur->type = REDICT_REPLY_INTEGER; break; case ',': - cur->type = REDIS_REPLY_DOUBLE; + cur->type = REDICT_REPLY_DOUBLE; break; case '_': - cur->type = REDIS_REPLY_NIL; + cur->type = REDICT_REPLY_NIL; break; case '$': - cur->type = REDIS_REPLY_STRING; + cur->type = REDICT_REPLY_STRING; break; case '*': - cur->type = REDIS_REPLY_ARRAY; + cur->type = REDICT_REPLY_ARRAY; break; case '%': - cur->type = REDIS_REPLY_MAP; + cur->type = REDICT_REPLY_MAP; break; case '|': - cur->type = REDIS_REPLY_ATTR; + cur->type = REDICT_REPLY_ATTR; break; case '~': - cur->type = REDIS_REPLY_SET; + cur->type = REDICT_REPLY_SET; break; case '#': - cur->type = REDIS_REPLY_BOOL; + cur->type = REDICT_REPLY_BOOL; break; case '=': - cur->type = REDIS_REPLY_VERB; + cur->type = REDICT_REPLY_VERB; break; case '>': - cur->type = REDIS_REPLY_PUSH; + cur->type = REDICT_REPLY_PUSH; break; case '(': - cur->type = REDIS_REPLY_BIGNUM; + cur->type = REDICT_REPLY_BIGNUM; break; default: - __redisReaderSetErrorProtocolByte(r,*p); - return REDIS_ERR; + __redictReaderSetErrorProtocolByte(r,*p); + return REDICT_ERR; } } else { /* could not consume 1 byte */ - return REDIS_ERR; + return REDICT_ERR; } } /* process typed item */ switch(cur->type) { - case REDIS_REPLY_ERROR: - case REDIS_REPLY_STATUS: - case REDIS_REPLY_INTEGER: - case REDIS_REPLY_DOUBLE: - case REDIS_REPLY_NIL: - case REDIS_REPLY_BOOL: - case REDIS_REPLY_BIGNUM: + case REDICT_REPLY_ERROR: + case REDICT_REPLY_STATUS: + case REDICT_REPLY_INTEGER: + case REDICT_REPLY_DOUBLE: + case REDICT_REPLY_NIL: + case REDICT_REPLY_BOOL: + case REDICT_REPLY_BIGNUM: return processLineItem(r); - case REDIS_REPLY_STRING: - case REDIS_REPLY_VERB: + case REDICT_REPLY_STRING: + case REDICT_REPLY_VERB: return processBulkItem(r); - case REDIS_REPLY_ARRAY: - case REDIS_REPLY_MAP: - case REDIS_REPLY_ATTR: - case REDIS_REPLY_SET: - case REDIS_REPLY_PUSH: + case REDICT_REPLY_ARRAY: + case REDICT_REPLY_MAP: + case REDICT_REPLY_ATTR: + case REDICT_REPLY_SET: + case REDICT_REPLY_PUSH: return processAggregateItem(r); default: assert(NULL); - return REDIS_ERR; /* Avoid warning. */ + return REDICT_ERR; /* Avoid warning. */ } } -redisReader *redisReaderCreateWithFunctions(redisReplyObjectFunctions *fn) { - redisReader *r; +redictReader *redictReaderCreateWithFunctions(redictReplyObjectFunctions *fn) { + redictReader *r; - r = hi_calloc(1,sizeof(redisReader)); + r = hi_calloc(1,sizeof(redictReader)); if (r == NULL) return NULL; @@ -649,28 +649,28 @@ redisReader *redisReaderCreateWithFunctions(redisReplyObjectFunctions *fn) { if (r->buf == NULL) goto oom; - r->task = hi_calloc(REDIS_READER_STACK_SIZE, sizeof(*r->task)); + r->task = hi_calloc(REDICT_READER_STACK_SIZE, sizeof(*r->task)); if (r->task == NULL) goto oom; - for (; r->tasks < REDIS_READER_STACK_SIZE; r->tasks++) { + for (; r->tasks < REDICT_READER_STACK_SIZE; r->tasks++) { r->task[r->tasks] = hi_calloc(1, sizeof(**r->task)); if (r->task[r->tasks] == NULL) goto oom; } r->fn = fn; - r->maxbuf = REDIS_READER_MAX_BUF; - r->maxelements = REDIS_READER_MAX_ARRAY_ELEMENTS; + r->maxbuf = REDICT_READER_MAX_BUF; + r->maxelements = REDICT_READER_MAX_ARRAY_ELEMENTS; r->ridx = -1; return r; oom: - redisReaderFree(r); + redictReaderFree(r); return NULL; } -void redisReaderFree(redisReader *r) { +void redictReaderFree(redictReader *r) { if (r == NULL) return; @@ -690,12 +690,12 @@ void redisReaderFree(redisReader *r) { hi_free(r); } -int redisReaderFeed(redisReader *r, const char *buf, size_t len) { +int redictReaderFeed(redictReader *r, const char *buf, size_t len) { sds newbuf; /* Return early when this reader is in an erroneous state. */ if (r->err) - return REDIS_ERR; + return REDICT_ERR; /* Copy the provided buffer. */ if (buf != NULL && len >= 1) { @@ -715,24 +715,24 @@ int redisReaderFeed(redisReader *r, const char *buf, size_t len) { r->len = sdslen(r->buf); } - return REDIS_OK; + return REDICT_OK; oom: - __redisReaderSetErrorOOM(r); - return REDIS_ERR; + __redictReaderSetErrorOOM(r); + return REDICT_ERR; } -int redisReaderGetReply(redisReader *r, void **reply) { +int redictReaderGetReply(redictReader *r, void **reply) { /* Default target pointer to NULL. */ if (reply != NULL) *reply = NULL; /* Return early when this reader is in an erroneous state. */ if (r->err) - return REDIS_ERR; + return REDICT_ERR; /* When the buffer is empty, there will never be a reply. */ if (r->len == 0) - return REDIS_OK; + return REDICT_OK; /* Set first item to process when the stack is empty. */ if (r->ridx == -1) { @@ -747,17 +747,17 @@ int redisReaderGetReply(redisReader *r, void **reply) { /* Process items in reply. */ while (r->ridx >= 0) - if (processItem(r) != REDIS_OK) + if (processItem(r) != REDICT_OK) break; /* Return ASAP when an error occurred. */ if (r->err) - return REDIS_ERR; + return REDICT_ERR; /* Discard part of the buffer when we've consumed at least 1k, to avoid * doing unnecessary calls to memmove() in sds.c. */ if (r->pos >= 1024) { - if (sdsrange(r->buf,r->pos,-1) < 0) return REDIS_ERR; + if (sdsrange(r->buf,r->pos,-1) < 0) return REDICT_ERR; r->pos = 0; r->len = sdslen(r->buf); } @@ -771,5 +771,5 @@ int redisReaderGetReply(redisReader *r, void **reply) { } r->reply = NULL; } - return REDIS_OK; + return REDICT_OK; } diff --git a/read.h b/read.h index 9beff7e..f36587a 100644 --- a/read.h +++ b/read.h @@ -12,69 +12,69 @@ */ -#ifndef __HIREDIS_READ_H -#define __HIREDIS_READ_H +#ifndef __HIREDICT_READ_H +#define __HIREDICT_READ_H #include /* for size_t */ -#define REDIS_ERR -1 -#define REDIS_OK 0 +#define REDICT_ERR -1 +#define REDICT_OK 0 /* When an error occurs, the err flag in a context is set to hold the type of - * error that occurred. REDIS_ERR_IO means there was an I/O error and you + * error that occurred. REDICT_ERR_IO means there was an I/O error and you * should use the "errno" variable to find out what is wrong. * For other values, the "errstr" field will hold a description. */ -#define REDIS_ERR_IO 1 /* Error in read or write */ -#define REDIS_ERR_EOF 3 /* End of file */ -#define REDIS_ERR_PROTOCOL 4 /* Protocol error */ -#define REDIS_ERR_OOM 5 /* Out of memory */ -#define REDIS_ERR_TIMEOUT 6 /* Timed out */ -#define REDIS_ERR_OTHER 2 /* Everything else... */ - -#define REDIS_REPLY_STRING 1 -#define REDIS_REPLY_ARRAY 2 -#define REDIS_REPLY_INTEGER 3 -#define REDIS_REPLY_NIL 4 -#define REDIS_REPLY_STATUS 5 -#define REDIS_REPLY_ERROR 6 -#define REDIS_REPLY_DOUBLE 7 -#define REDIS_REPLY_BOOL 8 -#define REDIS_REPLY_MAP 9 -#define REDIS_REPLY_SET 10 -#define REDIS_REPLY_ATTR 11 -#define REDIS_REPLY_PUSH 12 -#define REDIS_REPLY_BIGNUM 13 -#define REDIS_REPLY_VERB 14 +#define REDICT_ERR_IO 1 /* Error in read or write */ +#define REDICT_ERR_EOF 3 /* End of file */ +#define REDICT_ERR_PROTOCOL 4 /* Protocol error */ +#define REDICT_ERR_OOM 5 /* Out of memory */ +#define REDICT_ERR_TIMEOUT 6 /* Timed out */ +#define REDICT_ERR_OTHER 2 /* Everything else... */ + +#define REDICT_REPLY_STRING 1 +#define REDICT_REPLY_ARRAY 2 +#define REDICT_REPLY_INTEGER 3 +#define REDICT_REPLY_NIL 4 +#define REDICT_REPLY_STATUS 5 +#define REDICT_REPLY_ERROR 6 +#define REDICT_REPLY_DOUBLE 7 +#define REDICT_REPLY_BOOL 8 +#define REDICT_REPLY_MAP 9 +#define REDICT_REPLY_SET 10 +#define REDICT_REPLY_ATTR 11 +#define REDICT_REPLY_PUSH 12 +#define REDICT_REPLY_BIGNUM 13 +#define REDICT_REPLY_VERB 14 /* Default max unused reader buffer. */ -#define REDIS_READER_MAX_BUF (1024*16) +#define REDICT_READER_MAX_BUF (1024*16) /* Default multi-bulk element limit */ -#define REDIS_READER_MAX_ARRAY_ELEMENTS ((1LL<<32) - 1) +#define REDICT_READER_MAX_ARRAY_ELEMENTS ((1LL<<32) - 1) #ifdef __cplusplus extern "C" { #endif -typedef struct redisReadTask { +typedef struct redictReadTask { int type; long long elements; /* number of elements in multibulk container */ int idx; /* index in parent (array) object */ void *obj; /* holds user-generated value for a read task */ - struct redisReadTask *parent; /* parent task */ + struct redictReadTask *parent; /* parent task */ void *privdata; /* user-settable arbitrary field */ -} redisReadTask; - -typedef struct redisReplyObjectFunctions { - void *(*createString)(const redisReadTask*, char*, size_t); - void *(*createArray)(const redisReadTask*, size_t); - void *(*createInteger)(const redisReadTask*, long long); - void *(*createDouble)(const redisReadTask*, double, char*, size_t); - void *(*createNil)(const redisReadTask*); - void *(*createBool)(const redisReadTask*, int); +} redictReadTask; + +typedef struct redictReplyObjectFunctions { + void *(*createString)(const redictReadTask*, char*, size_t); + void *(*createArray)(const redictReadTask*, size_t); + void *(*createInteger)(const redictReadTask*, long long); + void *(*createDouble)(const redictReadTask*, double, char*, size_t); + void *(*createNil)(const redictReadTask*); + void *(*createBool)(const redictReadTask*, int); void (*freeObject)(void*); -} redisReplyObjectFunctions; +} redictReplyObjectFunctions; -typedef struct redisReader { +typedef struct redictReader { int err; /* Error flags, 0 when there is no error */ char errstr[128]; /* String representation of error when applicable */ @@ -84,25 +84,25 @@ typedef struct redisReader { size_t maxbuf; /* Max length of unused buffer */ long long maxelements; /* Max multi-bulk elements */ - redisReadTask **task; + redictReadTask **task; int tasks; int ridx; /* Index of current read task */ void *reply; /* Temporary reply pointer */ - redisReplyObjectFunctions *fn; + redictReplyObjectFunctions *fn; void *privdata; -} redisReader; +} redictReader; /* Public API for the protocol parser. */ -redisReader *redisReaderCreateWithFunctions(redisReplyObjectFunctions *fn); -void redisReaderFree(redisReader *r); -int redisReaderFeed(redisReader *r, const char *buf, size_t len); -int redisReaderGetReply(redisReader *r, void **reply); - -#define redisReaderSetPrivdata(_r, _p) (int)(((redisReader*)(_r))->privdata = (_p)) -#define redisReaderGetObject(_r) (((redisReader*)(_r))->reply) -#define redisReaderGetError(_r) (((redisReader*)(_r))->errstr) +redictReader *redictReaderCreateWithFunctions(redictReplyObjectFunctions *fn); +void redictReaderFree(redictReader *r); +int redictReaderFeed(redictReader *r, const char *buf, size_t len); +int redictReaderGetReply(redictReader *r, void **reply); + +#define redictReaderSetPrivdata(_r, _p) (int)(((redictReader*)(_r))->privdata = (_p)) +#define redictReaderGetObject(_r) (((redictReader*)(_r))->reply) +#define redictReaderGetError(_r) (((redictReader*)(_r))->errstr) #ifdef __cplusplus } diff --git a/sds.h b/sds.h index 23c7e0c..c6a5760 100644 --- a/sds.h +++ b/sds.h @@ -257,7 +257,7 @@ void *sds_malloc(size_t size); void *sds_realloc(void *ptr, size_t size); void sds_free(void *ptr); -#ifdef REDIS_TEST +#ifdef REDICT_TEST int sdsTest(int argc, char *argv[]); #endif diff --git a/sockcompat.c b/sockcompat.c index 850e8ed..6c82cce 100644 --- a/sockcompat.c +++ b/sockcompat.c @@ -9,7 +9,7 @@ * */ -#define REDIS_SOCKCOMPAT_IMPLEMENTATION +#define REDICT_SOCKCOMPAT_IMPLEMENTATION #include "sockcompat.h" #ifdef _WIN32 @@ -242,7 +242,7 @@ int win32_poll(struct pollfd *fds, nfds_t nfds, int timeout) { return ret != SOCKET_ERROR ? ret : -1; } -int win32_redisKeepAlive(SOCKET sockfd, int interval_ms) { +int win32_redictKeepAlive(SOCKET sockfd, int interval_ms) { struct tcp_keepalive cfg; DWORD bytes_in; int res; diff --git a/sockcompat.h b/sockcompat.h index 281db37..7354f51 100644 --- a/sockcompat.h +++ b/sockcompat.h @@ -53,9 +53,9 @@ ssize_t win32_send(SOCKET sockfd, const void *buf, size_t len, int flags); typedef ULONG nfds_t; int win32_poll(struct pollfd *fds, nfds_t nfds, int timeout); -int win32_redisKeepAlive(SOCKET sockfd, int interval_ms); +int win32_redictKeepAlive(SOCKET sockfd, int interval_ms); -#ifndef REDIS_SOCKCOMPAT_IMPLEMENTATION +#ifndef REDICT_SOCKCOMPAT_IMPLEMENTATION #define getaddrinfo(node, service, hints, res) win32_getaddrinfo(node, service, hints, res) #undef gai_strerror #define gai_strerror(errcode) win32_gai_strerror(errcode) @@ -70,7 +70,7 @@ int win32_redisKeepAlive(SOCKET sockfd, int interval_ms); #define recv(sockfd, buf, len, flags) win32_recv(sockfd, buf, len, flags) #define send(sockfd, buf, len, flags) win32_send(sockfd, buf, len, flags) #define poll(fds, nfds, timeout) win32_poll(fds, nfds, timeout) -#endif /* REDIS_SOCKCOMPAT_IMPLEMENTATION */ +#endif /* REDICT_SOCKCOMPAT_IMPLEMENTATION */ #endif /* _WIN32 */ #endif /* __SOCKCOMPAT_H */ diff --git a/ssl.c b/ssl.c index 1fcf45c..19c49a2 100644 --- a/ssl.c +++ b/ssl.c @@ -44,10 +44,10 @@ #define OPENSSL_1_1_0 0x10100000L -void __redisSetError(redisContext *c, int type, const char *str); +void __redictSetError(redictContext *c, int type, const char *str); -struct redisSSLContext { - /* Associated OpenSSL SSL_CTX as created by redisCreateSSLContext() */ +struct redictSSLContext { + /* Associated OpenSSL SSL_CTX as created by redictCreateSSLContext() */ SSL_CTX *ssl_ctx; /* Requested SNI, or NULL */ @@ -55,7 +55,7 @@ struct redisSSLContext { }; /* The SSL connection context is attached to SSL/TLS connections as a privdata. */ -typedef struct redisSSL { +typedef struct redictSSL { /** * OpenSSL SSL object. */ @@ -75,10 +75,10 @@ typedef struct redisSSL { * should resume whenever a read takes place, if possible */ int pendingWrite; -} redisSSL; +} redictSSL; /* Forward declaration */ -redisContextFuncs redisContextSSLFuncs; +redictContextFuncs redictContextSSLFuncs; /** * OpenSSL global initialization and locking handling callbacks. @@ -86,10 +86,10 @@ redisContextFuncs redisContextSSLFuncs; */ #if OPENSSL_VERSION_NUMBER < OPENSSL_1_1_0 -#define HIREDIS_USE_CRYPTO_LOCKS +#define HIREDICT_USE_CRYPTO_LOCKS #endif -#ifdef HIREDIS_USE_CRYPTO_LOCKS +#ifdef HIREDICT_USE_CRYPTO_LOCKS #ifdef _WIN32 typedef CRITICAL_SECTION sslLockType; static void sslLockInit(sslLockType* l) { @@ -133,60 +133,60 @@ static int initOpensslLocks(void) { unsigned ii, nlocks; if (CRYPTO_get_locking_callback() != NULL) { /* Someone already set the callback before us. Don't destroy it! */ - return REDIS_OK; + return REDICT_OK; } nlocks = CRYPTO_num_locks(); ossl_locks = hi_malloc(sizeof(*ossl_locks) * nlocks); if (ossl_locks == NULL) - return REDIS_ERR; + return REDICT_ERR; for (ii = 0; ii < nlocks; ii++) { sslLockInit(ossl_locks + ii); } CRYPTO_set_locking_callback(opensslDoLock); - return REDIS_OK; + return REDICT_OK; } -#endif /* HIREDIS_USE_CRYPTO_LOCKS */ +#endif /* HIREDICT_USE_CRYPTO_LOCKS */ -int redisInitOpenSSL(void) +int redictInitOpenSSL(void) { SSL_library_init(); -#ifdef HIREDIS_USE_CRYPTO_LOCKS +#ifdef HIREDICT_USE_CRYPTO_LOCKS initOpensslLocks(); #endif - return REDIS_OK; + return REDICT_OK; } /** - * redisSSLContext helper context destruction. + * redictSSLContext helper context destruction. */ -const char *redisSSLContextGetError(redisSSLContextError error) +const char *redictSSLContextGetError(redictSSLContextError error) { switch (error) { - case REDIS_SSL_CTX_NONE: + case REDICT_SSL_CTX_NONE: return "No Error"; - case REDIS_SSL_CTX_CREATE_FAILED: + case REDICT_SSL_CTX_CREATE_FAILED: return "Failed to create OpenSSL SSL_CTX"; - case REDIS_SSL_CTX_CERT_KEY_REQUIRED: + case REDICT_SSL_CTX_CERT_KEY_REQUIRED: return "Client cert and key must both be specified or skipped"; - case REDIS_SSL_CTX_CA_CERT_LOAD_FAILED: + case REDICT_SSL_CTX_CA_CERT_LOAD_FAILED: return "Failed to load CA Certificate or CA Path"; - case REDIS_SSL_CTX_CLIENT_CERT_LOAD_FAILED: + case REDICT_SSL_CTX_CLIENT_CERT_LOAD_FAILED: return "Failed to load client certificate"; - case REDIS_SSL_CTX_PRIVATE_KEY_LOAD_FAILED: + case REDICT_SSL_CTX_PRIVATE_KEY_LOAD_FAILED: return "Failed to load private key"; - case REDIS_SSL_CTX_OS_CERTSTORE_OPEN_FAILED: + case REDICT_SSL_CTX_OS_CERTSTORE_OPEN_FAILED: return "Failed to open system certificate store"; - case REDIS_SSL_CTX_OS_CERT_ADD_FAILED: + case REDICT_SSL_CTX_OS_CERT_ADD_FAILED: return "Failed to add CA certificates obtained from system to the SSL context"; default: return "Unknown error code"; } } -void redisFreeSSLContext(redisSSLContext *ctx) +void redictFreeSSLContext(redictSSLContext *ctx) { if (!ctx) return; @@ -206,26 +206,26 @@ void redisFreeSSLContext(redisSSLContext *ctx) /** - * redisSSLContext helper context initialization. + * redictSSLContext helper context initialization. */ -redisSSLContext *redisCreateSSLContext(const char *cacert_filename, const char *capath, +redictSSLContext *redictCreateSSLContext(const char *cacert_filename, const char *capath, const char *cert_filename, const char *private_key_filename, - const char *server_name, redisSSLContextError *error) + const char *server_name, redictSSLContextError *error) { - redisSSLOptions options = { + redictSSLOptions options = { .cacert_filename = cacert_filename, .capath = capath, .cert_filename = cert_filename, .private_key_filename = private_key_filename, .server_name = server_name, - .verify_mode = REDIS_SSL_VERIFY_PEER, + .verify_mode = REDICT_SSL_VERIFY_PEER, }; - return redisCreateSSLContextWithOptions(&options, error); + return redictCreateSSLContextWithOptions(&options, error); } -redisSSLContext *redisCreateSSLContextWithOptions(redisSSLOptions *options, redisSSLContextError *error) { +redictSSLContext *redictCreateSSLContextWithOptions(redictSSLOptions *options, redictSSLContextError *error) { const char *cacert_filename = options->cacert_filename; const char *capath = options->capath; const char *cert_filename = options->cert_filename; @@ -237,7 +237,7 @@ redisSSLContext *redisCreateSSLContextWithOptions(redisSSLOptions *options, redi PCCERT_CONTEXT win_ctx = NULL; #endif - redisSSLContext *ctx = hi_calloc(1, sizeof(redisSSLContext)); + redictSSLContext *ctx = hi_calloc(1, sizeof(redictSSLContext)); if (ctx == NULL) goto error; @@ -250,7 +250,7 @@ redisSSLContext *redisCreateSSLContextWithOptions(redisSSLOptions *options, redi ctx->ssl_ctx = SSL_CTX_new(ssl_method); if (!ctx->ssl_ctx) { - if (error) *error = REDIS_SSL_CTX_CREATE_FAILED; + if (error) *error = REDICT_SSL_CTX_CREATE_FAILED; goto error; } @@ -264,7 +264,7 @@ redisSSLContext *redisCreateSSLContextWithOptions(redisSSLOptions *options, redi if ((cert_filename != NULL && private_key_filename == NULL) || (private_key_filename != NULL && cert_filename == NULL)) { - if (error) *error = REDIS_SSL_CTX_CERT_KEY_REQUIRED; + if (error) *error = REDICT_SSL_CTX_CERT_KEY_REQUIRED; goto error; } @@ -273,7 +273,7 @@ redisSSLContext *redisCreateSSLContextWithOptions(redisSSLOptions *options, redi if (0 == strcmp(cacert_filename, "wincert")) { win_store = CertOpenSystemStore(NULL, "Root"); if (!win_store) { - if (error) *error = REDIS_SSL_CTX_OS_CERTSTORE_OPEN_FAILED; + if (error) *error = REDICT_SSL_CTX_OS_CERTSTORE_OPEN_FAILED; goto error; } X509_STORE* store = SSL_CTX_get_cert_store(ctx->ssl_ctx); @@ -284,7 +284,7 @@ redisSSLContext *redisCreateSSLContextWithOptions(redisSSLOptions *options, redi if ((1 != X509_STORE_add_cert(store, x509)) || (1 != SSL_CTX_add_client_CA(ctx->ssl_ctx, x509))) { - if (error) *error = REDIS_SSL_CTX_OS_CERT_ADD_FAILED; + if (error) *error = REDICT_SSL_CTX_OS_CERT_ADD_FAILED; goto error; } X509_free(x509); @@ -295,23 +295,23 @@ redisSSLContext *redisCreateSSLContextWithOptions(redisSSLOptions *options, redi } else #endif if (!SSL_CTX_load_verify_locations(ctx->ssl_ctx, cacert_filename, capath)) { - if (error) *error = REDIS_SSL_CTX_CA_CERT_LOAD_FAILED; + if (error) *error = REDICT_SSL_CTX_CA_CERT_LOAD_FAILED; goto error; } } else { if (!SSL_CTX_set_default_verify_paths(ctx->ssl_ctx)) { - if (error) *error = REDIS_SSL_CTX_CLIENT_DEFAULT_CERT_FAILED; + if (error) *error = REDICT_SSL_CTX_CLIENT_DEFAULT_CERT_FAILED; goto error; } } if (cert_filename) { if (!SSL_CTX_use_certificate_chain_file(ctx->ssl_ctx, cert_filename)) { - if (error) *error = REDIS_SSL_CTX_CLIENT_CERT_LOAD_FAILED; + if (error) *error = REDICT_SSL_CTX_CLIENT_CERT_LOAD_FAILED; goto error; } if (!SSL_CTX_use_PrivateKey_file(ctx->ssl_ctx, private_key_filename, SSL_FILETYPE_PEM)) { - if (error) *error = REDIS_SSL_CTX_PRIVATE_KEY_LOAD_FAILED; + if (error) *error = REDICT_SSL_CTX_PRIVATE_KEY_LOAD_FAILED; goto error; } } @@ -326,7 +326,7 @@ error: CertFreeCertificateContext(win_ctx); CertCloseStore(win_store, 0); #endif - redisFreeSSLContext(ctx); + redictFreeSSLContext(ctx); return NULL; } @@ -335,19 +335,19 @@ error: */ -static int redisSSLConnect(redisContext *c, SSL *ssl) { +static int redictSSLConnect(redictContext *c, SSL *ssl) { if (c->privctx) { - __redisSetError(c, REDIS_ERR_OTHER, "redictContext was already associated"); - return REDIS_ERR; + __redictSetError(c, REDICT_ERR_OTHER, "redictContext was already associated"); + return REDICT_ERR; } - redisSSL *rssl = hi_calloc(1, sizeof(redisSSL)); + redictSSL *rssl = hi_calloc(1, sizeof(redictSSL)); if (rssl == NULL) { - __redisSetError(c, REDIS_ERR_OOM, "Out of memory"); - return REDIS_ERR; + __redictSetError(c, REDICT_ERR_OOM, "Out of memory"); + return REDICT_ERR; } - c->funcs = &redisContextSSLFuncs; + c->funcs = &redictContextSSLFuncs; rssl->ssl = ssl; SSL_set_mode(rssl->ssl, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); @@ -358,14 +358,14 @@ static int redisSSLConnect(redisContext *c, SSL *ssl) { int rv = SSL_connect(rssl->ssl); if (rv == 1) { c->privctx = rssl; - return REDIS_OK; + return REDICT_OK; } rv = SSL_get_error(rssl->ssl, rv); - if (((c->flags & REDIS_BLOCK) == 0) && + if (((c->flags & REDICT_BLOCK) == 0) && (rv == SSL_ERROR_WANT_READ || rv == SSL_ERROR_WANT_WRITE)) { c->privctx = rssl; - return REDIS_OK; + return REDICT_OK; } if (c->err == 0) { @@ -377,64 +377,64 @@ static int redisSSLConnect(redisContext *c, SSL *ssl) { snprintf(err,sizeof(err)-1,"SSL_connect failed: %s", ERR_reason_error_string(e)); } - __redisSetError(c, REDIS_ERR_IO, err); + __redictSetError(c, REDICT_ERR_IO, err); } hi_free(rssl); - return REDIS_ERR; + return REDICT_ERR; } /** - * A wrapper around redisSSLConnect() for users who manage their own context and + * A wrapper around redictSSLConnect() for users who manage their own context and * create their own SSL object. */ -int redisInitiateSSL(redisContext *c, SSL *ssl) { - return redisSSLConnect(c, ssl); +int redictInitiateSSL(redictContext *c, SSL *ssl) { + return redictSSLConnect(c, ssl); } /** - * A wrapper around redisSSLConnect() for users who use redisSSLContext and don't + * A wrapper around redictSSLConnect() for users who use redictSSLContext and don't * manage their own SSL objects. */ -int redisInitiateSSLWithContext(redisContext *c, redisSSLContext *redis_ssl_ctx) +int redictInitiateSSLWithContext(redictContext *c, redictSSLContext *redict_ssl_ctx) { - if (!c || !redis_ssl_ctx) - return REDIS_ERR; + if (!c || !redict_ssl_ctx) + return REDICT_ERR; - /* We want to verify that redisSSLConnect() won't fail on this, as it will + /* We want to verify that redictSSLConnect() won't fail on this, as it will * not own the SSL object in that case and we'll end up leaking. */ if (c->privctx) - return REDIS_ERR; + return REDICT_ERR; - SSL *ssl = SSL_new(redis_ssl_ctx->ssl_ctx); + SSL *ssl = SSL_new(redict_ssl_ctx->ssl_ctx); if (!ssl) { - __redisSetError(c, REDIS_ERR_OTHER, "Couldn't create new SSL instance"); + __redictSetError(c, REDICT_ERR_OTHER, "Couldn't create new SSL instance"); goto error; } - if (redis_ssl_ctx->server_name) { - if (!SSL_set_tlsext_host_name(ssl, redis_ssl_ctx->server_name)) { - __redisSetError(c, REDIS_ERR_OTHER, "Failed to set server_name/SNI"); + if (redict_ssl_ctx->server_name) { + if (!SSL_set_tlsext_host_name(ssl, redict_ssl_ctx->server_name)) { + __redictSetError(c, REDICT_ERR_OTHER, "Failed to set server_name/SNI"); goto error; } } - if (redisSSLConnect(c, ssl) != REDIS_OK) { + if (redictSSLConnect(c, ssl) != REDICT_OK) { goto error; } - return REDIS_OK; + return REDICT_OK; error: if (ssl) SSL_free(ssl); - return REDIS_ERR; + return REDICT_ERR; } -static int maybeCheckWant(redisSSL *rssl, int rv) { +static int maybeCheckWant(redictSSL *rssl, int rv) { /** * If the error is WANT_READ or WANT_WRITE, the appropriate flags are set * and true is returned. False is returned otherwise @@ -451,11 +451,11 @@ static int maybeCheckWant(redisSSL *rssl, int rv) { } /** - * Implementation of redisContextFuncs for SSL connections. + * Implementation of redictContextFuncs for SSL connections. */ -static void redisSSLFree(void *privctx){ - redisSSL *rsc = privctx; +static void redictSSLFree(void *privctx){ + redictSSL *rsc = privctx; if (!rsc) return; if (rsc->ssl) { @@ -465,18 +465,18 @@ static void redisSSLFree(void *privctx){ hi_free(rsc); } -static ssize_t redisSSLRead(redisContext *c, char *buf, size_t bufcap) { - redisSSL *rssl = c->privctx; +static ssize_t redictSSLRead(redictContext *c, char *buf, size_t bufcap) { + redictSSL *rssl = c->privctx; int nread = SSL_read(rssl->ssl, buf, bufcap); if (nread > 0) { return nread; } else if (nread == 0) { - __redisSetError(c, REDIS_ERR_EOF, "Server closed the connection"); + __redictSetError(c, REDICT_ERR_EOF, "Server closed the connection"); return -1; } else { int err = SSL_get_error(rssl->ssl, nread); - if (c->flags & REDIS_BLOCK) { + if (c->flags & REDICT_BLOCK) { /** * In blocking mode, we should never end up in a situation where * we get an error without it being an actual error, except @@ -490,7 +490,7 @@ static ssize_t redisSSLRead(redisContext *c, char *buf, size_t bufcap) { if (errno == EAGAIN) { msg = "Resource temporarily unavailable"; } - __redisSetError(c, REDIS_ERR_IO, msg); + __redictSetError(c, REDICT_ERR_IO, msg); return -1; } } @@ -501,14 +501,14 @@ static ssize_t redisSSLRead(redisContext *c, char *buf, size_t bufcap) { if (maybeCheckWant(rssl, err)) { return 0; } else { - __redisSetError(c, REDIS_ERR_IO, NULL); + __redictSetError(c, REDICT_ERR_IO, NULL); return -1; } } } -static ssize_t redisSSLWrite(redisContext *c) { - redisSSL *rssl = c->privctx; +static ssize_t redictSSLWrite(redictContext *c) { + redictSSL *rssl = c->privctx; size_t len = rssl->lastLen ? rssl->lastLen : sdslen(c->obuf); int rv = SSL_write(rssl->ssl, c->obuf, len); @@ -519,20 +519,20 @@ static ssize_t redisSSLWrite(redisContext *c) { rssl->lastLen = len; int err = SSL_get_error(rssl->ssl, rv); - if ((c->flags & REDIS_BLOCK) == 0 && maybeCheckWant(rssl, err)) { + if ((c->flags & REDICT_BLOCK) == 0 && maybeCheckWant(rssl, err)) { return 0; } else { - __redisSetError(c, REDIS_ERR_IO, NULL); + __redictSetError(c, REDICT_ERR_IO, NULL); return -1; } } return rv; } -static void redisSSLAsyncRead(redisAsyncContext *ac) { +static void redictSSLAsyncRead(redictAsyncContext *ac) { int rv; - redisSSL *rssl = ac->c.privctx; - redisContext *c = &ac->c; + redictSSL *rssl = ac->c.privctx; + redictContext *c = &ac->c; rssl->wantRead = 0; @@ -541,33 +541,33 @@ static void redisSSLAsyncRead(redisAsyncContext *ac) { /* This is probably just a write event */ rssl->pendingWrite = 0; - rv = redisBufferWrite(c, &done); - if (rv == REDIS_ERR) { - __redisAsyncDisconnect(ac); + rv = redictBufferWrite(c, &done); + if (rv == REDICT_ERR) { + __redictAsyncDisconnect(ac); return; } else if (!done) { _EL_ADD_WRITE(ac); } } - rv = redisBufferRead(c); - if (rv == REDIS_ERR) { - __redisAsyncDisconnect(ac); + rv = redictBufferRead(c); + if (rv == REDICT_ERR) { + __redictAsyncDisconnect(ac); } else { _EL_ADD_READ(ac); - redisProcessCallbacks(ac); + redictProcessCallbacks(ac); } } -static void redisSSLAsyncWrite(redisAsyncContext *ac) { +static void redictSSLAsyncWrite(redictAsyncContext *ac) { int rv, done = 0; - redisSSL *rssl = ac->c.privctx; - redisContext *c = &ac->c; + redictSSL *rssl = ac->c.privctx; + redictContext *c = &ac->c; rssl->pendingWrite = 0; - rv = redisBufferWrite(c, &done); - if (rv == REDIS_ERR) { - __redisAsyncDisconnect(ac); + rv = redictBufferWrite(c, &done); + if (rv == REDICT_ERR) { + __redictAsyncDisconnect(ac); return; } @@ -589,12 +589,12 @@ static void redisSSLAsyncWrite(redisAsyncContext *ac) { _EL_ADD_READ(ac); } -redisContextFuncs redisContextSSLFuncs = { - .close = redisNetClose, - .free_privctx = redisSSLFree, - .async_read = redisSSLAsyncRead, - .async_write = redisSSLAsyncWrite, - .read = redisSSLRead, - .write = redisSSLWrite +redictContextFuncs redictContextSSLFuncs = { + .close = redictNetClose, + .free_privctx = redictSSLFree, + .async_read = redictSSLAsyncRead, + .async_write = redictSSLAsyncWrite, + .read = redictSSLRead, + .write = redictSSLWrite }; diff --git a/test.c b/test.c index 7703292..48d53e9 100644 --- a/test.c +++ b/test.c @@ -27,10 +27,10 @@ #include "hiredict.h" #include "async.h" #include "adapters/poll.h" -#ifdef HIREDIS_TEST_SSL +#ifdef HIREDICT_TEST_SSL #include "hiredict_ssl.h" #endif -#ifdef HIREDIS_TEST_ASYNC +#ifdef HIREDICT_TEST_ASYNC #include "adapters/libevent.h" #include #endif @@ -77,8 +77,8 @@ struct pushCounters { static int insecure_calloc_calls; -#ifdef HIREDIS_TEST_SSL -redisSSLContext *_ssl_ctx = NULL; +#ifdef HIREDICT_TEST_SSL +redictSSLContext *_ssl_ctx = NULL; #endif /* The following lines make up our testing "framework" :) */ @@ -115,27 +115,27 @@ static long long usec(void) { #define assert(e) (void)(e) #endif -#define redisTestPanic(msg) \ +#define redictTestPanic(msg) \ do { \ fprintf(stderr, "PANIC: %s (In function \"%s\", file \"%s\", line %d)\n", \ msg, __func__, __FILE__, __LINE__); \ exit(1); \ } while (1) -/* Helper to extract Redis version information. Aborts on any failure. */ -#define REDIS_VERSION_FIELD "redict_version:" -void get_redis_version(redisContext *c, int *majorptr, int *minorptr) { - redisReply *reply; +/* Helper to extract Redict version information. Aborts on any failure. */ +#define REDICT_VERSION_FIELD "redict_version:" +void get_redict_version(redictContext *c, int *majorptr, int *minorptr) { + redictReply *reply; char *eptr, *s, *e; int major, minor; - reply = redisCommand(c, "INFO"); - if (reply == NULL || c->err || reply->type != REDIS_REPLY_STRING) + reply = redictCommand(c, "INFO"); + if (reply == NULL || c->err || reply->type != REDICT_REPLY_STRING) goto abort; - if ((s = strstr(reply->str, REDIS_VERSION_FIELD)) == NULL) + if ((s = strstr(reply->str, REDICT_VERSION_FIELD)) == NULL) goto abort; - s += strlen(REDIS_VERSION_FIELD); + s += strlen(REDICT_VERSION_FIELD); /* We need a field terminator and at least 'x.y.z' (5) bytes of data */ if ((e = strstr(s, "\r\n")) == NULL || (e - s) < 5) @@ -159,18 +159,18 @@ abort: exit(1); } -static redisContext *select_database(redisContext *c) { - redisReply *reply; +static redictContext *select_database(redictContext *c) { + redictReply *reply; /* Switch to DB 9 for testing, now that we know we can chat. */ - reply = redisCommand(c,"SELECT 9"); + reply = redictCommand(c,"SELECT 9"); assert(reply != NULL); freeReplyObject(reply); /* Make sure the DB is empty */ - reply = redisCommand(c,"DBSIZE"); + reply = redictCommand(c,"DBSIZE"); assert(reply != NULL); - if (reply->type == REDIS_REPLY_INTEGER && reply->integer == 0) { + if (reply->type == REDICT_REPLY_INTEGER && reply->integer == 0) { /* Awesome, DB 9 is empty and we can continue. */ freeReplyObject(reply); } else { @@ -182,49 +182,49 @@ static redisContext *select_database(redisContext *c) { } /* Switch protocol */ -static void send_hello(redisContext *c, int version) { - redisReply *reply; +static void send_hello(redictContext *c, int version) { + redictReply *reply; int expected; - reply = redisCommand(c, "HELLO %d", version); - expected = version == 3 ? REDIS_REPLY_MAP : REDIS_REPLY_ARRAY; + reply = redictCommand(c, "HELLO %d", version); + expected = version == 3 ? REDICT_REPLY_MAP : REDICT_REPLY_ARRAY; assert(reply != NULL && reply->type == expected); freeReplyObject(reply); } /* Togggle client tracking */ -static void send_client_tracking(redisContext *c, const char *str) { - redisReply *reply; +static void send_client_tracking(redictContext *c, const char *str) { + redictReply *reply; - reply = redisCommand(c, "CLIENT TRACKING %s", str); - assert(reply != NULL && reply->type == REDIS_REPLY_STATUS); + reply = redictCommand(c, "CLIENT TRACKING %s", str); + assert(reply != NULL && reply->type == REDICT_REPLY_STATUS); freeReplyObject(reply); } -static int disconnect(redisContext *c, int keep_fd) { - redisReply *reply; +static int disconnect(redictContext *c, int keep_fd) { + redictReply *reply; /* Make sure we're on DB 9. */ - reply = redisCommand(c,"SELECT 9"); + reply = redictCommand(c,"SELECT 9"); assert(reply != NULL); freeReplyObject(reply); - reply = redisCommand(c,"FLUSHDB"); + reply = redictCommand(c,"FLUSHDB"); assert(reply != NULL); freeReplyObject(reply); /* Free the context as well, but keep the fd if requested. */ if (keep_fd) - return redisFreeKeepFd(c); - redisFree(c); + return redictFreeKeepFd(c); + redictFree(c); return -1; } -static void do_ssl_handshake(redisContext *c) { -#ifdef HIREDIS_TEST_SSL - redisInitiateSSLWithContext(c, _ssl_ctx); +static void do_ssl_handshake(redictContext *c) { +#ifdef HIREDICT_TEST_SSL + redictInitiateSSLWithContext(c, _ssl_ctx); if (c->err) { printf("SSL error: %s\n", c->errstr); - redisFree(c); + redictFree(c); exit(1); } #else @@ -232,25 +232,25 @@ static void do_ssl_handshake(redisContext *c) { #endif } -static redisContext *do_connect(struct config config) { - redisContext *c = NULL; +static redictContext *do_connect(struct config config) { + redictContext *c = NULL; if (config.type == CONN_TCP) { - c = redisConnect(config.tcp.host, config.tcp.port); + c = redictConnect(config.tcp.host, config.tcp.port); } else if (config.type == CONN_SSL) { - c = redisConnect(config.ssl.host, config.ssl.port); + c = redictConnect(config.ssl.host, config.ssl.port); } else if (config.type == CONN_UNIX) { - c = redisConnectUnix(config.unix_sock.path); + c = redictConnectUnix(config.unix_sock.path); } else if (config.type == CONN_FD) { /* Create a dummy connection just to get an fd to inherit */ - redisContext *dummy_ctx = redisConnectUnix(config.unix_sock.path); + redictContext *dummy_ctx = redictConnectUnix(config.unix_sock.path); if (dummy_ctx) { int fd = disconnect(dummy_ctx, 1); printf("Connecting to inherited fd %d\n", fd); - c = redisConnectFd(fd); + c = redictConnectFd(fd); } } else { - redisTestPanic("Unknown connection type!"); + redictTestPanic("Unknown connection type!"); } if (c == NULL) { @@ -258,7 +258,7 @@ static redisContext *do_connect(struct config config) { exit(1); } else if (c->err) { printf("Connection error: %s\n", c->errstr); - redisFree(c); + redictFree(c); exit(1); } @@ -269,8 +269,8 @@ static redisContext *do_connect(struct config config) { return select_database(c); } -static void do_reconnect(redisContext *c, struct config config) { - redisReconnect(c); +static void do_reconnect(redictContext *c, struct config config) { + redictReconnect(c); if (config.type == CONN_SSL) { do_ssl_handshake(c); @@ -282,43 +282,43 @@ static void test_format_commands(void) { int len; test("Format command without interpolation: "); - len = redisFormatCommand(&cmd,"SET foo bar"); + len = redictFormatCommand(&cmd,"SET foo bar"); test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n",len) == 0 && len == 4+4+(3+2)+4+(3+2)+4+(3+2)); hi_free(cmd); test("Format command with %%s string interpolation: "); - len = redisFormatCommand(&cmd,"SET %s %s","foo","bar"); + len = redictFormatCommand(&cmd,"SET %s %s","foo","bar"); test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n",len) == 0 && len == 4+4+(3+2)+4+(3+2)+4+(3+2)); hi_free(cmd); test("Format command with %%s and an empty string: "); - len = redisFormatCommand(&cmd,"SET %s %s","foo",""); + len = redictFormatCommand(&cmd,"SET %s %s","foo",""); test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$0\r\n\r\n",len) == 0 && len == 4+4+(3+2)+4+(3+2)+4+(0+2)); hi_free(cmd); test("Format command with an empty string in between proper interpolations: "); - len = redisFormatCommand(&cmd,"SET %s %s","","foo"); + len = redictFormatCommand(&cmd,"SET %s %s","","foo"); test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$0\r\n\r\n$3\r\nfoo\r\n",len) == 0 && len == 4+4+(3+2)+4+(0+2)+4+(3+2)); hi_free(cmd); test("Format command with %%b string interpolation: "); - len = redisFormatCommand(&cmd,"SET %b %b","foo",(size_t)3,"b\0r",(size_t)3); + len = redictFormatCommand(&cmd,"SET %b %b","foo",(size_t)3,"b\0r",(size_t)3); test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nb\0r\r\n",len) == 0 && len == 4+4+(3+2)+4+(3+2)+4+(3+2)); hi_free(cmd); test("Format command with %%b and an empty string: "); - len = redisFormatCommand(&cmd,"SET %b %b","foo",(size_t)3,"",(size_t)0); + len = redictFormatCommand(&cmd,"SET %b %b","foo",(size_t)3,"",(size_t)0); test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$0\r\n\r\n",len) == 0 && len == 4+4+(3+2)+4+(3+2)+4+(0+2)); hi_free(cmd); test("Format command with literal %%: "); - len = redisFormatCommand(&cmd,"SET %% %%"); + len = redictFormatCommand(&cmd,"SET %% %%"); test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$1\r\n%\r\n$1\r\n%\r\n",len) == 0 && len == 4+4+(3+2)+4+(1+2)+4+(1+2)); hi_free(cmd); @@ -329,7 +329,7 @@ static void test_format_commands(void) { #define INTEGER_WIDTH_TEST(fmt, type) do { \ type value = 123; \ test("Format command with printf-delegation (" #type "): "); \ - len = redisFormatCommand(&cmd,"key:%08" fmt " str:%s", value, "hello"); \ + len = redictFormatCommand(&cmd,"key:%08" fmt " str:%s", value, "hello"); \ test_cond(strncmp(cmd,"*2\r\n$12\r\nkey:00000123\r\n$9\r\nstr:hello\r\n",len) == 0 && \ len == 4+5+(12+2)+4+(9+2)); \ hi_free(cmd); \ @@ -338,7 +338,7 @@ static void test_format_commands(void) { #define FLOAT_WIDTH_TEST(type) do { \ type value = 123.0; \ test("Format command with printf-delegation (" #type "): "); \ - len = redisFormatCommand(&cmd,"key:%08.3f str:%s", value, "hello"); \ + len = redictFormatCommand(&cmd,"key:%08.3f str:%s", value, "hello"); \ test_cond(strncmp(cmd,"*2\r\n$12\r\nkey:0123.000\r\n$9\r\nstr:hello\r\n",len) == 0 && \ len == 4+5+(12+2)+4+(9+2)); \ hi_free(cmd); \ @@ -358,11 +358,11 @@ static void test_format_commands(void) { FLOAT_WIDTH_TEST(double); test("Format command with unhandled printf format (specifier 'p' not supported): "); - len = redisFormatCommand(&cmd,"key:%08p %b",(void*)1234,"foo",(size_t)3); + len = redictFormatCommand(&cmd,"key:%08p %b",(void*)1234,"foo",(size_t)3); test_cond(len == -1); test("Format command with invalid printf format (specifier missing): "); - len = redisFormatCommand(&cmd,"%-"); + len = redictFormatCommand(&cmd,"%-"); test_cond(len == -1); const char *argv[3]; @@ -373,13 +373,13 @@ static void test_format_commands(void) { int argc = 3; test("Format command by passing argc/argv without lengths: "); - len = redisFormatCommandArgv(&cmd,argc,argv,NULL); + len = redictFormatCommandArgv(&cmd,argc,argv,NULL); test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n",len) == 0 && len == 4+4+(3+2)+4+(3+2)+4+(3+2)); hi_free(cmd); test("Format command by passing argc/argv with lengths: "); - len = redisFormatCommandArgv(&cmd,argc,argv,lens); + len = redictFormatCommandArgv(&cmd,argc,argv,lens); test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$7\r\nfoo\0xxx\r\n$3\r\nbar\r\n",len) == 0 && len == 4+4+(3+2)+4+(7+2)+4+(3+2)); hi_free(cmd); @@ -388,22 +388,22 @@ static void test_format_commands(void) { sds_cmd = NULL; test("Format command into sds by passing argc/argv without lengths: "); - len = redisFormatSdsCommandArgv(&sds_cmd,argc,argv,NULL); + len = redictFormatSdsCommandArgv(&sds_cmd,argc,argv,NULL); test_cond(strncmp(sds_cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n",len) == 0 && len == 4+4+(3+2)+4+(3+2)+4+(3+2)); sdsfree(sds_cmd); sds_cmd = NULL; test("Format command into sds by passing argc/argv with lengths: "); - len = redisFormatSdsCommandArgv(&sds_cmd,argc,argv,lens); + len = redictFormatSdsCommandArgv(&sds_cmd,argc,argv,lens); test_cond(strncmp(sds_cmd,"*3\r\n$3\r\nSET\r\n$7\r\nfoo\0xxx\r\n$3\r\nbar\r\n",len) == 0 && len == 4+4+(3+2)+4+(7+2)+4+(3+2)); sdsfree(sds_cmd); } static void test_append_formatted_commands(struct config config) { - redisContext *c; - redisReply *reply; + redictContext *c; + redictReply *reply; char *cmd; int len; @@ -411,11 +411,11 @@ static void test_append_formatted_commands(struct config config) { test("Append format command: "); - len = redisFormatCommand(&cmd, "SET foo bar"); + len = redictFormatCommand(&cmd, "SET foo bar"); - test_cond(redisAppendFormattedCommand(c, cmd, len) == REDIS_OK); + test_cond(redictAppendFormattedCommand(c, cmd, len) == REDICT_OK); - assert(redisGetReply(c, (void*)&reply) == REDIS_OK); + assert(redictGetReply(c, (void*)&reply) == REDICT_OK); hi_free(cmd); freeReplyObject(reply); @@ -424,155 +424,155 @@ static void test_append_formatted_commands(struct config config) { } static void test_tcp_options(struct config cfg) { - redisContext *c; + redictContext *c; c = do_connect(cfg); test("We can enable TCP_KEEPALIVE: "); - test_cond(redisEnableKeepAlive(c) == REDIS_OK); + test_cond(redictEnableKeepAlive(c) == REDICT_OK); #ifdef TCP_USER_TIMEOUT test("We can set TCP_USER_TIMEOUT: "); - test_cond(redisSetTcpUserTimeout(c, 100) == REDIS_OK); + test_cond(redictSetTcpUserTimeout(c, 100) == REDICT_OK); #else test("Setting TCP_USER_TIMEOUT errors when unsupported: "); - test_cond(redisSetTcpUserTimeout(c, 100) == REDIS_ERR && c->err == REDIS_ERR_IO); + test_cond(redictSetTcpUserTimeout(c, 100) == REDICT_ERR && c->err == REDICT_ERR_IO); #endif - redisFree(c); + redictFree(c); } static void test_unix_keepalive(struct config cfg) { - redisContext *c; - redisReply *r; + redictContext *c; + redictReply *r; c = do_connect(cfg); test("Setting TCP_KEEPALIVE on a unix socket returns an error: "); - test_cond(redisEnableKeepAlive(c) == REDIS_ERR && c->err == 0); + test_cond(redictEnableKeepAlive(c) == REDICT_ERR && c->err == 0); test("Setting TCP_KEEPALIVE on a unix socket doesn't break the connection: "); - r = redisCommand(c, "PING"); - test_cond(r != NULL && r->type == REDIS_REPLY_STATUS && r->len == 4 && + r = redictCommand(c, "PING"); + test_cond(r != NULL && r->type == REDICT_REPLY_STATUS && r->len == 4 && !memcmp(r->str, "PONG", 4)); freeReplyObject(r); - redisFree(c); + redictFree(c); } static void test_reply_reader(void) { - redisReader *reader; + redictReader *reader; void *reply, *root; int ret; int i; test("Error handling in reply parser: "); - reader = redisReaderCreate(); - redisReaderFeed(reader,(char*)"@foo\r\n",6); - ret = redisReaderGetReply(reader,NULL); - test_cond(ret == REDIS_ERR && + reader = redictReaderCreate(); + redictReaderFeed(reader,(char*)"@foo\r\n",6); + ret = redictReaderGetReply(reader,NULL); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr,"Protocol error, got \"@\" as reply type byte") == 0); - redisReaderFree(reader); + redictReaderFree(reader); /* when the reply already contains multiple items, they must be free'd * on an error. valgrind will bark when this doesn't happen. */ test("Memory cleanup in reply parser: "); - reader = redisReaderCreate(); - redisReaderFeed(reader,(char*)"*2\r\n",4); - redisReaderFeed(reader,(char*)"$5\r\nhello\r\n",11); - redisReaderFeed(reader,(char*)"@foo\r\n",6); - ret = redisReaderGetReply(reader,NULL); - test_cond(ret == REDIS_ERR && + reader = redictReaderCreate(); + redictReaderFeed(reader,(char*)"*2\r\n",4); + redictReaderFeed(reader,(char*)"$5\r\nhello\r\n",11); + redictReaderFeed(reader,(char*)"@foo\r\n",6); + ret = redictReaderGetReply(reader,NULL); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr,"Protocol error, got \"@\" as reply type byte") == 0); - redisReaderFree(reader); + redictReaderFree(reader); - reader = redisReaderCreate(); + reader = redictReaderCreate(); test("Can handle arbitrarily nested multi-bulks: "); for (i = 0; i < 128; i++) { - redisReaderFeed(reader,(char*)"*1\r\n", 4); + redictReaderFeed(reader,(char*)"*1\r\n", 4); } - redisReaderFeed(reader,(char*)"$6\r\nLOLWUT\r\n",12); - ret = redisReaderGetReply(reader,&reply); + redictReaderFeed(reader,(char*)"$6\r\nLOLWUT\r\n",12); + ret = redictReaderGetReply(reader,&reply); root = reply; /* Keep track of the root reply */ - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_ARRAY && - ((redisReply*)reply)->elements == 1); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_ARRAY && + ((redictReply*)reply)->elements == 1); test("Can parse arbitrarily nested multi-bulks correctly: "); while(i--) { - assert(reply != NULL && ((redisReply*)reply)->type == REDIS_REPLY_ARRAY); - reply = ((redisReply*)reply)->element[0]; + assert(reply != NULL && ((redictReply*)reply)->type == REDICT_REPLY_ARRAY); + reply = ((redictReply*)reply)->element[0]; } - test_cond(((redisReply*)reply)->type == REDIS_REPLY_STRING && - !memcmp(((redisReply*)reply)->str, "LOLWUT", 6)); + test_cond(((redictReply*)reply)->type == REDICT_REPLY_STRING && + !memcmp(((redictReply*)reply)->str, "LOLWUT", 6)); freeReplyObject(root); - redisReaderFree(reader); + redictReaderFree(reader); test("Correctly parses LLONG_MAX: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, ":9223372036854775807\r\n",22); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_INTEGER && - ((redisReply*)reply)->integer == LLONG_MAX); + reader = redictReaderCreate(); + redictReaderFeed(reader, ":9223372036854775807\r\n",22); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_INTEGER && + ((redictReply*)reply)->integer == LLONG_MAX); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Set error when > LLONG_MAX: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, ":9223372036854775808\r\n",22); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_ERR && + reader = redictReaderCreate(); + redictReaderFeed(reader, ":9223372036854775808\r\n",22); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr,"Bad integer value") == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Correctly parses LLONG_MIN: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, ":-9223372036854775808\r\n",23); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_INTEGER && - ((redisReply*)reply)->integer == LLONG_MIN); + reader = redictReaderCreate(); + redictReaderFeed(reader, ":-9223372036854775808\r\n",23); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_INTEGER && + ((redictReply*)reply)->integer == LLONG_MIN); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Set error when < LLONG_MIN: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, ":-9223372036854775809\r\n",23); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_ERR && + reader = redictReaderCreate(); + redictReaderFeed(reader, ":-9223372036854775809\r\n",23); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr,"Bad integer value") == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Set error when array < -1: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "*-2\r\n+asdf\r\n",12); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_ERR && + reader = redictReaderCreate(); + redictReaderFeed(reader, "*-2\r\n+asdf\r\n",12); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr,"Multi-bulk length out of range") == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Set error when bulk < -1: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "$-2\r\nasdf\r\n",11); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_ERR && + reader = redictReaderCreate(); + redictReaderFeed(reader, "$-2\r\nasdf\r\n",11); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr,"Bulk string length out of range") == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Can configure maximum multi-bulk elements: "); - reader = redisReaderCreate(); + reader = redictReaderCreate(); reader->maxelements = 1024; - redisReaderFeed(reader, "*1025\r\n", 7); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_ERR && + redictReaderFeed(reader, "*1025\r\n", 7); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr, "Multi-bulk length out of range") == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Multi-bulk never overflows regardless of maxelements: "); size_t bad_mbulk_len = (SIZE_MAX / sizeof(void *)) + 3; @@ -580,307 +580,307 @@ static void test_reply_reader(void) { snprintf(bad_mbulk_reply, sizeof(bad_mbulk_reply), "*%llu\r\n+asdf\r\n", (unsigned long long) bad_mbulk_len); - reader = redisReaderCreate(); + reader = redictReaderCreate(); reader->maxelements = 0; /* Don't rely on default limit */ - redisReaderFeed(reader, bad_mbulk_reply, strlen(bad_mbulk_reply)); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_ERR && strcasecmp(reader->errstr, "Out of memory") == 0); + redictReaderFeed(reader, bad_mbulk_reply, strlen(bad_mbulk_reply)); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr, "Out of memory") == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); #if LLONG_MAX > SIZE_MAX test("Set error when array > SIZE_MAX: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "*9223372036854775807\r\n+asdf\r\n",29); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_ERR && + reader = redictReaderCreate(); + redictReaderFeed(reader, "*9223372036854775807\r\n+asdf\r\n",29); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr,"Multi-bulk length out of range") == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Set error when bulk > SIZE_MAX: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "$9223372036854775807\r\nasdf\r\n",28); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_ERR && + reader = redictReaderCreate(); + redictReaderFeed(reader, "$9223372036854775807\r\nasdf\r\n",28); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr,"Bulk string length out of range") == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); #endif test("Works with NULL functions for reply: "); - reader = redisReaderCreate(); + reader = redictReaderCreate(); reader->fn = NULL; - redisReaderFeed(reader,(char*)"+OK\r\n",5); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && reply == (void*)REDIS_REPLY_STATUS); - redisReaderFree(reader); + redictReaderFeed(reader,(char*)"+OK\r\n",5); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && reply == (void*)REDICT_REPLY_STATUS); + redictReaderFree(reader); test("Works when a single newline (\\r\\n) covers two calls to feed: "); - reader = redisReaderCreate(); + reader = redictReaderCreate(); reader->fn = NULL; - redisReaderFeed(reader,(char*)"+OK\r",4); - ret = redisReaderGetReply(reader,&reply); - assert(ret == REDIS_OK && reply == NULL); - redisReaderFeed(reader,(char*)"\n",1); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && reply == (void*)REDIS_REPLY_STATUS); - redisReaderFree(reader); + redictReaderFeed(reader,(char*)"+OK\r",4); + ret = redictReaderGetReply(reader,&reply); + assert(ret == REDICT_OK && reply == NULL); + redictReaderFeed(reader,(char*)"\n",1); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && reply == (void*)REDICT_REPLY_STATUS); + redictReaderFree(reader); test("Don't reset state after protocol error: "); - reader = redisReaderCreate(); + reader = redictReaderCreate(); reader->fn = NULL; - redisReaderFeed(reader,(char*)"x",1); - ret = redisReaderGetReply(reader,&reply); - assert(ret == REDIS_ERR); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_ERR && reply == NULL); - redisReaderFree(reader); + redictReaderFeed(reader,(char*)"x",1); + ret = redictReaderGetReply(reader,&reply); + assert(ret == REDICT_ERR); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_ERR && reply == NULL); + redictReaderFree(reader); test("Don't reset state after protocol error(not segfault): "); - reader = redisReaderCreate(); - redisReaderFeed(reader,(char*)"*3\r\n$3\r\nSET\r\n$5\r\nhello\r\n$", 25); - ret = redisReaderGetReply(reader,&reply); - assert(ret == REDIS_OK); - redisReaderFeed(reader,(char*)"3\r\nval\r\n", 8); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_ARRAY && - ((redisReply*)reply)->elements == 3); - freeReplyObject(reply); - redisReaderFree(reader); + reader = redictReaderCreate(); + redictReaderFeed(reader,(char*)"*3\r\n$3\r\nSET\r\n$5\r\nhello\r\n$", 25); + ret = redictReaderGetReply(reader,&reply); + assert(ret == REDICT_OK); + redictReaderFeed(reader,(char*)"3\r\nval\r\n", 8); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_ARRAY && + ((redictReply*)reply)->elements == 3); + freeReplyObject(reply); + redictReaderFree(reader); /* Regression test for issue #45 on GitHub. */ test("Don't do empty allocation for empty multi bulk: "); - reader = redisReaderCreate(); - redisReaderFeed(reader,(char*)"*0\r\n",4); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_ARRAY && - ((redisReply*)reply)->elements == 0); + reader = redictReaderCreate(); + redictReaderFeed(reader,(char*)"*0\r\n",4); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_ARRAY && + ((redictReply*)reply)->elements == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); /* RESP3 verbatim strings (GitHub issue #802) */ test("Can parse RESP3 verbatim strings: "); - reader = redisReaderCreate(); - redisReaderFeed(reader,(char*)"=10\r\ntxt:LOLWUT\r\n",17); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_VERB && - !memcmp(((redisReply*)reply)->str,"LOLWUT", 6)); + reader = redictReaderCreate(); + redictReaderFeed(reader,(char*)"=10\r\ntxt:LOLWUT\r\n",17); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_VERB && + !memcmp(((redictReply*)reply)->str,"LOLWUT", 6)); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); /* RESP3 push messages (Github issue #815) */ test("Can parse RESP3 push messages: "); - reader = redisReaderCreate(); - redisReaderFeed(reader,(char*)">2\r\n$6\r\nLOLWUT\r\n:42\r\n",21); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_PUSH && - ((redisReply*)reply)->elements == 2 && - ((redisReply*)reply)->element[0]->type == REDIS_REPLY_STRING && - !memcmp(((redisReply*)reply)->element[0]->str,"LOLWUT",6) && - ((redisReply*)reply)->element[1]->type == REDIS_REPLY_INTEGER && - ((redisReply*)reply)->element[1]->integer == 42); - freeReplyObject(reply); - redisReaderFree(reader); + reader = redictReaderCreate(); + redictReaderFeed(reader,(char*)">2\r\n$6\r\nLOLWUT\r\n:42\r\n",21); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_PUSH && + ((redictReply*)reply)->elements == 2 && + ((redictReply*)reply)->element[0]->type == REDICT_REPLY_STRING && + !memcmp(((redictReply*)reply)->element[0]->str,"LOLWUT",6) && + ((redictReply*)reply)->element[1]->type == REDICT_REPLY_INTEGER && + ((redictReply*)reply)->element[1]->integer == 42); + freeReplyObject(reply); + redictReaderFree(reader); test("Can parse RESP3 doubles: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, ",3.14159265358979323846\r\n",25); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_DOUBLE && - fabs(((redisReply*)reply)->dval - 3.14159265358979323846) < 0.00000001 && - ((redisReply*)reply)->len == 22 && - strcmp(((redisReply*)reply)->str, "3.14159265358979323846") == 0); + reader = redictReaderCreate(); + redictReaderFeed(reader, ",3.14159265358979323846\r\n",25); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_DOUBLE && + fabs(((redictReply*)reply)->dval - 3.14159265358979323846) < 0.00000001 && + ((redictReply*)reply)->len == 22 && + strcmp(((redictReply*)reply)->str, "3.14159265358979323846") == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Set error on invalid RESP3 double: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, ",3.14159\000265358979323846\r\n",26); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_ERR && + reader = redictReaderCreate(); + redictReaderFeed(reader, ",3.14159\000265358979323846\r\n",26); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr,"Bad double value") == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Correctly parses RESP3 double INFINITY: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, ",inf\r\n",6); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_DOUBLE && - isinf(((redisReply*)reply)->dval) && - ((redisReply*)reply)->dval > 0); + reader = redictReaderCreate(); + redictReaderFeed(reader, ",inf\r\n",6); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_DOUBLE && + isinf(((redictReply*)reply)->dval) && + ((redictReply*)reply)->dval > 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Correctly parses RESP3 double NaN: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, ",nan\r\n",6); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_DOUBLE && - isnan(((redisReply*)reply)->dval)); + reader = redictReaderCreate(); + redictReaderFeed(reader, ",nan\r\n",6); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_DOUBLE && + isnan(((redictReply*)reply)->dval)); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Correctly parses RESP3 double -Nan: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, ",-nan\r\n", 7); - ret = redisReaderGetReply(reader, &reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_DOUBLE && - isnan(((redisReply*)reply)->dval)); + reader = redictReaderCreate(); + redictReaderFeed(reader, ",-nan\r\n", 7); + ret = redictReaderGetReply(reader, &reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_DOUBLE && + isnan(((redictReply*)reply)->dval)); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Can parse RESP3 nil: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "_\r\n",3); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_NIL); + reader = redictReaderCreate(); + redictReaderFeed(reader, "_\r\n",3); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_NIL); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Set error on invalid RESP3 nil: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "_nil\r\n",6); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_ERR && + reader = redictReaderCreate(); + redictReaderFeed(reader, "_nil\r\n",6); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr,"Bad nil value") == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Can parse RESP3 bool (true): "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "#t\r\n",4); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_BOOL && - ((redisReply*)reply)->integer); + reader = redictReaderCreate(); + redictReaderFeed(reader, "#t\r\n",4); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_BOOL && + ((redictReply*)reply)->integer); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Can parse RESP3 bool (false): "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "#f\r\n",4); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_BOOL && - !((redisReply*)reply)->integer); + reader = redictReaderCreate(); + redictReaderFeed(reader, "#f\r\n",4); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_BOOL && + !((redictReply*)reply)->integer); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Set error on invalid RESP3 bool: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "#foobar\r\n",9); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_ERR && + reader = redictReaderCreate(); + redictReaderFeed(reader, "#foobar\r\n",9); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_ERR && strcasecmp(reader->errstr,"Bad bool value") == 0); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Can parse RESP3 map: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "%2\r\n+first\r\n:123\r\n$6\r\nsecond\r\n#t\r\n",34); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_MAP && - ((redisReply*)reply)->elements == 4 && - ((redisReply*)reply)->element[0]->type == REDIS_REPLY_STATUS && - ((redisReply*)reply)->element[0]->len == 5 && - !strcmp(((redisReply*)reply)->element[0]->str,"first") && - ((redisReply*)reply)->element[1]->type == REDIS_REPLY_INTEGER && - ((redisReply*)reply)->element[1]->integer == 123 && - ((redisReply*)reply)->element[2]->type == REDIS_REPLY_STRING && - ((redisReply*)reply)->element[2]->len == 6 && - !strcmp(((redisReply*)reply)->element[2]->str,"second") && - ((redisReply*)reply)->element[3]->type == REDIS_REPLY_BOOL && - ((redisReply*)reply)->element[3]->integer); - freeReplyObject(reply); - redisReaderFree(reader); + reader = redictReaderCreate(); + redictReaderFeed(reader, "%2\r\n+first\r\n:123\r\n$6\r\nsecond\r\n#t\r\n",34); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_MAP && + ((redictReply*)reply)->elements == 4 && + ((redictReply*)reply)->element[0]->type == REDICT_REPLY_STATUS && + ((redictReply*)reply)->element[0]->len == 5 && + !strcmp(((redictReply*)reply)->element[0]->str,"first") && + ((redictReply*)reply)->element[1]->type == REDICT_REPLY_INTEGER && + ((redictReply*)reply)->element[1]->integer == 123 && + ((redictReply*)reply)->element[2]->type == REDICT_REPLY_STRING && + ((redictReply*)reply)->element[2]->len == 6 && + !strcmp(((redictReply*)reply)->element[2]->str,"second") && + ((redictReply*)reply)->element[3]->type == REDICT_REPLY_BOOL && + ((redictReply*)reply)->element[3]->integer); + freeReplyObject(reply); + redictReaderFree(reader); test("Can parse RESP3 attribute: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "|2\r\n+foo\r\n:123\r\n+bar\r\n#t\r\n",26); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_ATTR && - ((redisReply*)reply)->elements == 4 && - ((redisReply*)reply)->element[0]->type == REDIS_REPLY_STATUS && - ((redisReply*)reply)->element[0]->len == 3 && - !strcmp(((redisReply*)reply)->element[0]->str,"foo") && - ((redisReply*)reply)->element[1]->type == REDIS_REPLY_INTEGER && - ((redisReply*)reply)->element[1]->integer == 123 && - ((redisReply*)reply)->element[2]->type == REDIS_REPLY_STATUS && - ((redisReply*)reply)->element[2]->len == 3 && - !strcmp(((redisReply*)reply)->element[2]->str,"bar") && - ((redisReply*)reply)->element[3]->type == REDIS_REPLY_BOOL && - ((redisReply*)reply)->element[3]->integer); - freeReplyObject(reply); - redisReaderFree(reader); + reader = redictReaderCreate(); + redictReaderFeed(reader, "|2\r\n+foo\r\n:123\r\n+bar\r\n#t\r\n",26); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_ATTR && + ((redictReply*)reply)->elements == 4 && + ((redictReply*)reply)->element[0]->type == REDICT_REPLY_STATUS && + ((redictReply*)reply)->element[0]->len == 3 && + !strcmp(((redictReply*)reply)->element[0]->str,"foo") && + ((redictReply*)reply)->element[1]->type == REDICT_REPLY_INTEGER && + ((redictReply*)reply)->element[1]->integer == 123 && + ((redictReply*)reply)->element[2]->type == REDICT_REPLY_STATUS && + ((redictReply*)reply)->element[2]->len == 3 && + !strcmp(((redictReply*)reply)->element[2]->str,"bar") && + ((redictReply*)reply)->element[3]->type == REDICT_REPLY_BOOL && + ((redictReply*)reply)->element[3]->integer); + freeReplyObject(reply); + redictReaderFree(reader); test("Can parse RESP3 set: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "~5\r\n+orange\r\n$5\r\napple\r\n#f\r\n:100\r\n:999\r\n",40); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_SET && - ((redisReply*)reply)->elements == 5 && - ((redisReply*)reply)->element[0]->type == REDIS_REPLY_STATUS && - ((redisReply*)reply)->element[0]->len == 6 && - !strcmp(((redisReply*)reply)->element[0]->str,"orange") && - ((redisReply*)reply)->element[1]->type == REDIS_REPLY_STRING && - ((redisReply*)reply)->element[1]->len == 5 && - !strcmp(((redisReply*)reply)->element[1]->str,"apple") && - ((redisReply*)reply)->element[2]->type == REDIS_REPLY_BOOL && - !((redisReply*)reply)->element[2]->integer && - ((redisReply*)reply)->element[3]->type == REDIS_REPLY_INTEGER && - ((redisReply*)reply)->element[3]->integer == 100 && - ((redisReply*)reply)->element[4]->type == REDIS_REPLY_INTEGER && - ((redisReply*)reply)->element[4]->integer == 999); - freeReplyObject(reply); - redisReaderFree(reader); + reader = redictReaderCreate(); + redictReaderFeed(reader, "~5\r\n+orange\r\n$5\r\napple\r\n#f\r\n:100\r\n:999\r\n",40); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_SET && + ((redictReply*)reply)->elements == 5 && + ((redictReply*)reply)->element[0]->type == REDICT_REPLY_STATUS && + ((redictReply*)reply)->element[0]->len == 6 && + !strcmp(((redictReply*)reply)->element[0]->str,"orange") && + ((redictReply*)reply)->element[1]->type == REDICT_REPLY_STRING && + ((redictReply*)reply)->element[1]->len == 5 && + !strcmp(((redictReply*)reply)->element[1]->str,"apple") && + ((redictReply*)reply)->element[2]->type == REDICT_REPLY_BOOL && + !((redictReply*)reply)->element[2]->integer && + ((redictReply*)reply)->element[3]->type == REDICT_REPLY_INTEGER && + ((redictReply*)reply)->element[3]->integer == 100 && + ((redictReply*)reply)->element[4]->type == REDICT_REPLY_INTEGER && + ((redictReply*)reply)->element[4]->integer == 999); + freeReplyObject(reply); + redictReaderFree(reader); test("Can parse RESP3 bignum: "); - reader = redisReaderCreate(); - redisReaderFeed(reader,"(3492890328409238509324850943850943825024385\r\n",46); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_BIGNUM && - ((redisReply*)reply)->len == 43 && - !strcmp(((redisReply*)reply)->str,"3492890328409238509324850943850943825024385")); + reader = redictReaderCreate(); + redictReaderFeed(reader,"(3492890328409238509324850943850943825024385\r\n",46); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_BIGNUM && + ((redictReply*)reply)->len == 43 && + !strcmp(((redictReply*)reply)->str,"3492890328409238509324850943850943825024385")); freeReplyObject(reply); - redisReaderFree(reader); + redictReaderFree(reader); test("Can parse RESP3 doubles in an array: "); - reader = redisReaderCreate(); - redisReaderFeed(reader, "*1\r\n,3.14159265358979323846\r\n",31); - ret = redisReaderGetReply(reader,&reply); - test_cond(ret == REDIS_OK && - ((redisReply*)reply)->type == REDIS_REPLY_ARRAY && - ((redisReply*)reply)->elements == 1 && - ((redisReply*)reply)->element[0]->type == REDIS_REPLY_DOUBLE && - fabs(((redisReply*)reply)->element[0]->dval - 3.14159265358979323846) < 0.00000001 && - ((redisReply*)reply)->element[0]->len == 22 && - strcmp(((redisReply*)reply)->element[0]->str, "3.14159265358979323846") == 0); - freeReplyObject(reply); - redisReaderFree(reader); + reader = redictReaderCreate(); + redictReaderFeed(reader, "*1\r\n,3.14159265358979323846\r\n",31); + ret = redictReaderGetReply(reader,&reply); + test_cond(ret == REDICT_OK && + ((redictReply*)reply)->type == REDICT_REPLY_ARRAY && + ((redictReply*)reply)->elements == 1 && + ((redictReply*)reply)->element[0]->type == REDICT_REPLY_DOUBLE && + fabs(((redictReply*)reply)->element[0]->dval - 3.14159265358979323846) < 0.00000001 && + ((redictReply*)reply)->element[0]->len == 22 && + strcmp(((redictReply*)reply)->element[0]->str, "3.14159265358979323846") == 0); + freeReplyObject(reply); + redictReaderFree(reader); } static void test_free_null(void) { - void *redisCtx = NULL; + void *redictCtx = NULL; void *reply = NULL; test("Don't fail when redictFree is passed a NULL value: "); - redisFree(redisCtx); - test_cond(redisCtx == NULL); + redictFree(redictCtx); + test_cond(redictCtx == NULL); test("Don't fail when freeReplyObject is passed a NULL value: "); freeReplyObject(reply); @@ -914,7 +914,7 @@ static void *hi_realloc_fail(void *ptr, size_t size) { static void test_allocator_injection(void) { void *ptr; - hiredisAllocFuncs ha = { + hiredictAllocFuncs ha = { .mallocFn = hi_malloc_fail, .callocFn = hi_calloc_fail, .reallocFn = hi_realloc_fail, @@ -922,44 +922,44 @@ static void test_allocator_injection(void) { .freeFn = free, }; - // Override hiredis allocators - hiredisSetAllocators(&ha); + // Override hiredict allocators + hiredictSetAllocators(&ha); test("redictContext uses injected allocators: "); - redisContext *c = redisConnect("localhost", 6379); + redictContext *c = redictConnect("localhost", 6379); test_cond(c == NULL); test("redictReader uses injected allocators: "); - redisReader *reader = redisReaderCreate(); + redictReader *reader = redictReaderCreate(); test_cond(reader == NULL); - /* Make sure hiredis itself protects against a non-overflow checking calloc */ + /* Make sure hiredict itself protects against a non-overflow checking calloc */ test("hiredict calloc wrapper protects against overflow: "); ha.callocFn = hi_calloc_insecure; - hiredisSetAllocators(&ha); + hiredictSetAllocators(&ha); ptr = hi_calloc((SIZE_MAX / sizeof(void*)) + 3, sizeof(void*)); test_cond(ptr == NULL && insecure_calloc_calls == 0); // Return allocators to default - hiredisResetAllocators(); + hiredictResetAllocators(); } -#define HIREDIS_BAD_DOMAIN "idontexist-noreally.com" +#define HIREDICT_BAD_DOMAIN "idontexist-noreally.com" static void test_blocking_connection_errors(void) { struct addrinfo hints = {.ai_family = AF_INET}; struct addrinfo *ai_tmp = NULL; - redisContext *c; + redictContext *c; - int rv = getaddrinfo(HIREDIS_BAD_DOMAIN, "6379", &hints, &ai_tmp); + int rv = getaddrinfo(HIREDICT_BAD_DOMAIN, "6379", &hints, &ai_tmp); if (rv != 0) { // Address does *not* exist test("Returns error when host cannot be resolved: "); // First see if this domain name *actually* resolves to NXDOMAIN - c = redisConnect(HIREDIS_BAD_DOMAIN, 6379); + c = redictConnect(HIREDICT_BAD_DOMAIN, 6379); test_cond( - c->err == REDIS_ERR_OTHER && + c->err == REDICT_ERR_OTHER && (strcmp(c->errstr, "Name or service not known") == 0 || - strcmp(c->errstr, "Can't resolve: " HIREDIS_BAD_DOMAIN) == 0 || + strcmp(c->errstr, "Can't resolve: " HIREDICT_BAD_DOMAIN) == 0 || strcmp(c->errstr, "Name does not resolve") == 0 || strcmp(c->errstr, "nodename nor servname provided, or not known") == 0 || strcmp(c->errstr, "node name or service name not known") == 0 || @@ -968,71 +968,71 @@ static void test_blocking_connection_errors(void) { strcmp(c->errstr, "hostname nor servname provided, or not known") == 0 || strcmp(c->errstr, "no address associated with name") == 0 || strcmp(c->errstr, "No such host is known. ") == 0)); - redisFree(c); + redictFree(c); } else { printf("Skipping NXDOMAIN test. Found evil ISP!\n"); freeaddrinfo(ai_tmp); } #ifndef _WIN32 - redisOptions opt = {0}; + redictOptions opt = {0}; struct timeval tv; test("Returns error when the port is not open: "); - c = redisConnect((char*)"localhost", 1); - test_cond(c->err == REDIS_ERR_IO && + c = redictConnect((char*)"localhost", 1); + test_cond(c->err == REDICT_ERR_IO && strcmp(c->errstr,"Connection refused") == 0); - redisFree(c); + redictFree(c); /* Verify we don't regress from the fix in PR #1180 */ test("We don't clobber connection exception with setsockopt error: "); tv = (struct timeval){.tv_sec = 0, .tv_usec = 500000}; opt.command_timeout = opt.connect_timeout = &tv; - REDIS_OPTIONS_SET_TCP(&opt, "localhost", 10337); - c = redisConnectWithOptions(&opt); - test_cond(c->err == REDIS_ERR_IO && + REDICT_OPTIONS_SET_TCP(&opt, "localhost", 10337); + c = redictConnectWithOptions(&opt); + test_cond(c->err == REDICT_ERR_IO && strcmp(c->errstr, "Connection refused") == 0); - redisFree(c); + redictFree(c); test("Returns error when the unix_sock socket path doesn't accept connections: "); - c = redisConnectUnix((char*)"/tmp/idontexist.sock"); - test_cond(c->err == REDIS_ERR_IO); /* Don't care about the message... */ - redisFree(c); + c = redictConnectUnix((char*)"/tmp/idontexist.sock"); + test_cond(c->err == REDICT_ERR_IO); /* Don't care about the message... */ + redictFree(c); #endif } /* Test push handler */ void push_handler(void *privdata, void *r) { struct pushCounters *pcounts = privdata; - redisReply *reply = r, *payload; + redictReply *reply = r, *payload; - assert(reply && reply->type == REDIS_REPLY_PUSH && reply->elements == 2); + assert(reply && reply->type == REDICT_REPLY_PUSH && reply->elements == 2); payload = reply->element[1]; - if (payload->type == REDIS_REPLY_ARRAY) { + if (payload->type == REDICT_REPLY_ARRAY) { payload = payload->element[0]; } - if (payload->type == REDIS_REPLY_STRING) { + if (payload->type == REDICT_REPLY_STRING) { pcounts->str++; - } else if (payload->type == REDIS_REPLY_NIL) { + } else if (payload->type == REDICT_REPLY_NIL) { pcounts->nil++; } freeReplyObject(reply); } -/* Dummy function just to test setting a callback with redisOptions */ -void push_handler_async(redisAsyncContext *ac, void *reply) { +/* Dummy function just to test setting a callback with redictOptions */ +void push_handler_async(redictAsyncContext *ac, void *reply) { (void)ac; (void)reply; } -static void test_resp3_push_handler(redisContext *c) { +static void test_resp3_push_handler(redictContext *c) { struct pushCounters pc = {0}; - redisPushFn *old = NULL; - redisReply *reply; + redictPushFn *old = NULL; + redictReply *reply; void *privdata; /* Switch to RESP3 and turn on client tracking */ @@ -1041,61 +1041,61 @@ static void test_resp3_push_handler(redisContext *c) { privdata = c->privdata; c->privdata = &pc; - reply = redisCommand(c, "GET key:0"); + reply = redictCommand(c, "GET key:0"); assert(reply != NULL); freeReplyObject(reply); test("RESP3 PUSH messages are handled out of band by default: "); - reply = redisCommand(c, "SET key:0 val:0"); - test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS); + reply = redictCommand(c, "SET key:0 val:0"); + test_cond(reply != NULL && reply->type == REDICT_REPLY_STATUS); freeReplyObject(reply); - assert((reply = redisCommand(c, "GET key:0")) != NULL); + assert((reply = redictCommand(c, "GET key:0")) != NULL); freeReplyObject(reply); - old = redisSetPushCallback(c, push_handler); + old = redictSetPushCallback(c, push_handler); test("We can set a custom RESP3 PUSH handler: "); - reply = redisCommand(c, "SET key:0 val:0"); - /* We need another command because depending on the version of Redis, the + reply = redictCommand(c, "SET key:0 val:0"); + /* We need another command because depending on the version of Redict, the * notification may be delivered after the command's reply. */ assert(reply != NULL); freeReplyObject(reply); - reply = redisCommand(c, "PING"); - test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS && pc.str == 1); + reply = redictCommand(c, "PING"); + test_cond(reply != NULL && reply->type == REDICT_REPLY_STATUS && pc.str == 1); freeReplyObject(reply); test("We properly handle a NIL invalidation payload: "); - reply = redisCommand(c, "FLUSHDB"); + reply = redictCommand(c, "FLUSHDB"); assert(reply != NULL); freeReplyObject(reply); - reply = redisCommand(c, "PING"); - test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS && pc.nil == 1); + reply = redictCommand(c, "PING"); + test_cond(reply != NULL && reply->type == REDICT_REPLY_STATUS && pc.nil == 1); freeReplyObject(reply); /* Unset the push callback and generate an invalidate message making * sure it is not handled out of band. */ test("With no handler, PUSH replies come in-band: "); - redisSetPushCallback(c, NULL); - assert((reply = redisCommand(c, "GET key:0")) != NULL); + redictSetPushCallback(c, NULL); + assert((reply = redictCommand(c, "GET key:0")) != NULL); freeReplyObject(reply); - assert((reply = redisCommand(c, "SET key:0 invalid")) != NULL); - /* Depending on Redis version, we may receive either push notification or + assert((reply = redictCommand(c, "SET key:0 invalid")) != NULL); + /* Depending on Redict version, we may receive either push notification or * status reply. Both cases are valid. */ - if (reply->type == REDIS_REPLY_STATUS) { + if (reply->type == REDICT_REPLY_STATUS) { freeReplyObject(reply); - reply = redisCommand(c, "PING"); + reply = redictCommand(c, "PING"); } - test_cond(reply->type == REDIS_REPLY_PUSH); + test_cond(reply->type == REDICT_REPLY_PUSH); freeReplyObject(reply); test("With no PUSH handler, no replies are lost: "); - assert(redisGetReply(c, (void**)&reply) == REDIS_OK); - test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS); + assert(redictGetReply(c, (void**)&reply) == REDICT_OK); + test_cond(reply != NULL && reply->type == REDICT_REPLY_STATUS); freeReplyObject(reply); /* Return to the originally set PUSH handler */ assert(old != NULL); - redisSetPushCallback(c, old); + redictSetPushCallback(c, old); /* Switch back to RESP2 and disable tracking */ c->privdata = privdata; @@ -1103,49 +1103,49 @@ static void test_resp3_push_handler(redisContext *c) { send_hello(c, 2); } -redisOptions get_redis_tcp_options(struct config config) { - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, config.tcp.host, config.tcp.port); +redictOptions get_redict_tcp_options(struct config config) { + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, config.tcp.host, config.tcp.port); return options; } static void test_resp3_push_options(struct config config) { - redisAsyncContext *ac; - redisContext *c; - redisOptions options; + redictAsyncContext *ac; + redictContext *c; + redictOptions options; test("We set a default RESP3 handler for redictContext: "); - options = get_redis_tcp_options(config); - assert((c = redisConnectWithOptions(&options)) != NULL); + options = get_redict_tcp_options(config); + assert((c = redictConnectWithOptions(&options)) != NULL); test_cond(c->push_cb != NULL); - redisFree(c); + redictFree(c); test("We don't set a default RESP3 push handler for redictAsyncContext: "); - options = get_redis_tcp_options(config); - assert((ac = redisAsyncConnectWithOptions(&options)) != NULL); + options = get_redict_tcp_options(config); + assert((ac = redictAsyncConnectWithOptions(&options)) != NULL); test_cond(ac->c.push_cb == NULL); - redisAsyncFree(ac); + redictAsyncFree(ac); - test("Our REDIS_OPT_NO_PUSH_AUTOFREE flag works: "); - options = get_redis_tcp_options(config); - options.options |= REDIS_OPT_NO_PUSH_AUTOFREE; - assert((c = redisConnectWithOptions(&options)) != NULL); + test("Our REDICT_OPT_NO_PUSH_AUTOFREE flag works: "); + options = get_redict_tcp_options(config); + options.options |= REDICT_OPT_NO_PUSH_AUTOFREE; + assert((c = redictConnectWithOptions(&options)) != NULL); test_cond(c->push_cb == NULL); - redisFree(c); + redictFree(c); test("We can use redictOptions to set a custom PUSH handler for redctsContext: "); - options = get_redis_tcp_options(config); + options = get_redict_tcp_options(config); options.push_cb = push_handler; - assert((c = redisConnectWithOptions(&options)) != NULL); + assert((c = redictConnectWithOptions(&options)) != NULL); test_cond(c->push_cb == push_handler); - redisFree(c); + redictFree(c); test("We can use redictOptions to set a custom PUSH handler for redictAsyncContext: "); - options = get_redis_tcp_options(config); + options = get_redict_tcp_options(config); options.async_push_cb = push_handler_async; - assert((ac = redisAsyncConnectWithOptions(&options)) != NULL); + assert((ac = redictAsyncConnectWithOptions(&options)) != NULL); test_cond(ac->push_cb == push_handler_async); - redisAsyncFree(ac); + redictAsyncFree(ac); } void free_privdata(void *privdata) { @@ -1155,52 +1155,52 @@ void free_privdata(void *privdata) { static void test_privdata_hooks(struct config config) { struct privdata data = {0}; - redisOptions options; - redisContext *c; + redictOptions options; + redictContext *c; test("We can use redictOptions to set privdata: "); - options = get_redis_tcp_options(config); - REDIS_OPTIONS_SET_PRIVDATA(&options, &data, free_privdata); - assert((c = redisConnectWithOptions(&options)) != NULL); + options = get_redict_tcp_options(config); + REDICT_OPTIONS_SET_PRIVDATA(&options, &data, free_privdata); + assert((c = redictConnectWithOptions(&options)) != NULL); test_cond(c->privdata == &data); test("Our privdata destructor fires when we free the context: "); - redisFree(c); + redictFree(c); test_cond(data.dtor_counter == 1); } static void test_blocking_connection(struct config config) { - redisContext *c; - redisReply *reply; + redictContext *c; + redictReply *reply; int major; c = do_connect(config); test("Is able to deliver commands: "); - reply = redisCommand(c,"PING"); - test_cond(reply->type == REDIS_REPLY_STATUS && + reply = redictCommand(c,"PING"); + test_cond(reply->type == REDICT_REPLY_STATUS && strcasecmp(reply->str,"pong") == 0) freeReplyObject(reply); test("Is a able to send commands verbatim: "); - reply = redisCommand(c,"SET foo bar"); - test_cond (reply->type == REDIS_REPLY_STATUS && + reply = redictCommand(c,"SET foo bar"); + test_cond (reply->type == REDICT_REPLY_STATUS && strcasecmp(reply->str,"ok") == 0) freeReplyObject(reply); test("%%s String interpolation works: "); - reply = redisCommand(c,"SET %s %s","foo","hello world"); + reply = redictCommand(c,"SET %s %s","foo","hello world"); freeReplyObject(reply); - reply = redisCommand(c,"GET foo"); - test_cond(reply->type == REDIS_REPLY_STRING && + reply = redictCommand(c,"GET foo"); + test_cond(reply->type == REDICT_REPLY_STRING && strcmp(reply->str,"hello world") == 0); freeReplyObject(reply); test("%%b String interpolation works: "); - reply = redisCommand(c,"SET %b %b","foo",(size_t)3,"hello\x00world",(size_t)11); + reply = redictCommand(c,"SET %b %b","foo",(size_t)3,"hello\x00world",(size_t)11); freeReplyObject(reply); - reply = redisCommand(c,"GET foo"); - test_cond(reply->type == REDIS_REPLY_STRING && + reply = redictCommand(c,"GET foo"); + test_cond(reply->type == REDICT_REPLY_STRING && memcmp(reply->str,"hello\x00world",11) == 0) test("Binary reply length is correct: "); @@ -1208,21 +1208,21 @@ static void test_blocking_connection(struct config config) { freeReplyObject(reply); test("Can parse nil replies: "); - reply = redisCommand(c,"GET nokey"); - test_cond(reply->type == REDIS_REPLY_NIL) + reply = redictCommand(c,"GET nokey"); + test_cond(reply->type == REDICT_REPLY_NIL) freeReplyObject(reply); /* test 7 */ test("Can parse integer replies: "); - reply = redisCommand(c,"INCR mycounter"); - test_cond(reply->type == REDIS_REPLY_INTEGER && reply->integer == 1) + reply = redictCommand(c,"INCR mycounter"); + test_cond(reply->type == REDICT_REPLY_INTEGER && reply->integer == 1) freeReplyObject(reply); test("Can parse multi bulk replies: "); - freeReplyObject(redisCommand(c,"LPUSH mylist foo")); - freeReplyObject(redisCommand(c,"LPUSH mylist bar")); - reply = redisCommand(c,"LRANGE mylist 0 -1"); - test_cond(reply->type == REDIS_REPLY_ARRAY && + freeReplyObject(redictCommand(c,"LPUSH mylist foo")); + freeReplyObject(redictCommand(c,"LPUSH mylist bar")); + reply = redictCommand(c,"LRANGE mylist 0 -1"); + test_cond(reply->type == REDICT_REPLY_ARRAY && reply->elements == 2 && !memcmp(reply->element[0]->str,"bar",3) && !memcmp(reply->element[1]->str,"foo",3)) @@ -1231,33 +1231,33 @@ static void test_blocking_connection(struct config config) { /* m/e with multi bulk reply *before* other reply. * specifically test ordering of reply items to parse. */ test("Can handle nested multi bulk replies: "); - freeReplyObject(redisCommand(c,"MULTI")); - freeReplyObject(redisCommand(c,"LRANGE mylist 0 -1")); - freeReplyObject(redisCommand(c,"PING")); - reply = (redisCommand(c,"EXEC")); - test_cond(reply->type == REDIS_REPLY_ARRAY && + freeReplyObject(redictCommand(c,"MULTI")); + freeReplyObject(redictCommand(c,"LRANGE mylist 0 -1")); + freeReplyObject(redictCommand(c,"PING")); + reply = (redictCommand(c,"EXEC")); + test_cond(reply->type == REDICT_REPLY_ARRAY && reply->elements == 2 && - reply->element[0]->type == REDIS_REPLY_ARRAY && + reply->element[0]->type == REDICT_REPLY_ARRAY && reply->element[0]->elements == 2 && !memcmp(reply->element[0]->element[0]->str,"bar",3) && !memcmp(reply->element[0]->element[1]->str,"foo",3) && - reply->element[1]->type == REDIS_REPLY_STATUS && + reply->element[1]->type == REDICT_REPLY_STATUS && strcasecmp(reply->element[1]->str,"pong") == 0); freeReplyObject(reply); test("Send command by passing argc/argv: "); const char *argv[3] = {"SET", "foo", "bar"}; size_t argvlen[3] = {3, 3, 3}; - reply = redisCommandArgv(c,3,argv,argvlen); - test_cond(reply->type == REDIS_REPLY_STATUS); + reply = redictCommandArgv(c,3,argv,argvlen); + test_cond(reply->type == REDICT_REPLY_STATUS); freeReplyObject(reply); - /* Make sure passing NULL to redisGetReply is safe */ + /* Make sure passing NULL to redictGetReply is safe */ test("Can pass NULL to redictGetReply: "); - assert(redisAppendCommand(c, "PING") == REDIS_OK); - test_cond(redisGetReply(c, NULL) == REDIS_OK); + assert(redictAppendCommand(c, "PING") == REDICT_OK); + test_cond(redictGetReply(c, NULL) == REDICT_OK); - get_redis_version(c, &major, NULL); + get_redict_version(c, &major, NULL); if (major >= 6) test_resp3_push_handler(c); test_resp3_push_options(config); @@ -1267,9 +1267,9 @@ static void test_blocking_connection(struct config config) { } /* Send DEBUG SLEEP 0 to detect if we have this command */ -static int detect_debug_sleep(redisContext *c) { +static int detect_debug_sleep(redictContext *c) { int detected; - redisReply *reply = redisCommand(c, "DEBUG SLEEP 0\r\n"); + redictReply *reply = redictCommand(c, "DEBUG SLEEP 0\r\n"); if (reply == NULL || c->err) { const char *cause = c->err ? c->errstr : "(none)"; @@ -1277,35 +1277,35 @@ static int detect_debug_sleep(redisContext *c) { exit(-1); } - detected = reply->type == REDIS_REPLY_STATUS; + detected = reply->type == REDICT_REPLY_STATUS; freeReplyObject(reply); return detected; } static void test_blocking_connection_timeouts(struct config config) { - redisContext *c; - redisReply *reply; + redictContext *c; + redictReply *reply; ssize_t s; const char *sleep_cmd = "DEBUG SLEEP 3\r\n"; struct timeval tv; c = do_connect(config); test("Successfully completes a command when the timeout is not exceeded: "); - reply = redisCommand(c,"SET foo fast"); + reply = redictCommand(c,"SET foo fast"); freeReplyObject(reply); tv.tv_sec = 0; tv.tv_usec = 10000; - redisSetTimeout(c, tv); - reply = redisCommand(c, "GET foo"); - test_cond(reply != NULL && reply->type == REDIS_REPLY_STRING && memcmp(reply->str, "fast", 4) == 0); + redictSetTimeout(c, tv); + reply = redictCommand(c, "GET foo"); + test_cond(reply != NULL && reply->type == REDICT_REPLY_STRING && memcmp(reply->str, "fast", 4) == 0); freeReplyObject(reply); disconnect(c, 0); c = do_connect(config); test("Does not return a reply when the command times out: "); if (detect_debug_sleep(c)) { - redisAppendFormattedCommand(c, sleep_cmd, strlen(sleep_cmd)); + redictAppendFormattedCommand(c, sleep_cmd, strlen(sleep_cmd)); // flush connection buffer without waiting for the reply s = c->funcs->write(c); @@ -1315,18 +1315,18 @@ static void test_blocking_connection_timeouts(struct config config) { tv.tv_sec = 0; tv.tv_usec = 10000; - redisSetTimeout(c, tv); - reply = redisCommand(c, "GET foo"); + redictSetTimeout(c, tv); + reply = redictCommand(c, "GET foo"); #ifndef _WIN32 - test_cond(s > 0 && reply == NULL && c->err == REDIS_ERR_IO && + test_cond(s > 0 && reply == NULL && c->err == REDICT_ERR_IO && strcmp(c->errstr, "Resource temporarily unavailable") == 0); #else - test_cond(s > 0 && reply == NULL && c->err == REDIS_ERR_TIMEOUT && + test_cond(s > 0 && reply == NULL && c->err == REDICT_ERR_TIMEOUT && strcmp(c->errstr, "recv timeout") == 0); #endif freeReplyObject(reply); - // wait for the DEBUG SLEEP to complete so that Redis server is unblocked for the following tests + // wait for the DEBUG SLEEP to complete so that Redict server is unblocked for the following tests millisleep(3000); } else { test_skipped(); @@ -1334,38 +1334,38 @@ static void test_blocking_connection_timeouts(struct config config) { test("Reconnect properly reconnects after a timeout: "); do_reconnect(c, config); - reply = redisCommand(c, "PING"); - test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS && strcmp(reply->str, "PONG") == 0); + reply = redictCommand(c, "PING"); + test_cond(reply != NULL && reply->type == REDICT_REPLY_STATUS && strcmp(reply->str, "PONG") == 0); freeReplyObject(reply); test("Reconnect properly uses owned parameters: "); config.tcp.host = "foo"; config.unix_sock.path = "foo"; do_reconnect(c, config); - reply = redisCommand(c, "PING"); - test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS && strcmp(reply->str, "PONG") == 0); + reply = redictCommand(c, "PING"); + test_cond(reply != NULL && reply->type == REDICT_REPLY_STATUS && strcmp(reply->str, "PONG") == 0); freeReplyObject(reply); disconnect(c, 0); } static void test_blocking_io_errors(struct config config) { - redisContext *c; - redisReply *reply; + redictContext *c; + redictReply *reply; void *_reply; int major, minor; /* Connect to target given by config. */ c = do_connect(config); - get_redis_version(c, &major, &minor); + get_redict_version(c, &major, &minor); test("Returns I/O error when the connection is lost: "); - reply = redisCommand(c,"QUIT"); + reply = redictCommand(c,"QUIT"); if (major > 2 || (major == 2 && minor > 0)) { /* > 2.0 returns OK on QUIT and read() should be issued once more * to know the descriptor is at EOF. */ test_cond(strcasecmp(reply->str,"OK") == 0 && - redisGetReply(c,&_reply) == REDIS_ERR); + redictGetReply(c,&_reply) == REDICT_ERR); freeReplyObject(reply); } else { test_cond(reply == NULL); @@ -1377,26 +1377,26 @@ static void test_blocking_io_errors(struct config config) { * On >2.0, QUIT will return with OK and another read(2) needed to be * issued to find out the socket was closed by the server. In both * conditions, the error will be set to EOF. */ - assert(c->err == REDIS_ERR_EOF && + assert(c->err == REDICT_ERR_EOF && strcmp(c->errstr,"Server closed the connection") == 0); #endif - redisFree(c); + redictFree(c); c = do_connect(config); test("Returns I/O error on socket timeout: "); struct timeval tv = { 0, 1000 }; - assert(redisSetTimeout(c,tv) == REDIS_OK); - int respcode = redisGetReply(c,&_reply); + assert(redictSetTimeout(c,tv) == REDICT_OK); + int respcode = redictGetReply(c,&_reply); #ifndef _WIN32 - test_cond(respcode == REDIS_ERR && c->err == REDIS_ERR_IO && errno == EAGAIN); + test_cond(respcode == REDICT_ERR && c->err == REDICT_ERR_IO && errno == EAGAIN); #else - test_cond(respcode == REDIS_ERR && c->err == REDIS_ERR_TIMEOUT); + test_cond(respcode == REDICT_ERR && c->err == REDICT_ERR_TIMEOUT); #endif - redisFree(c); + redictFree(c); } static void test_invalid_timeout_errors(struct config config) { - redisContext *c = NULL; + redictContext *c = NULL; test("Set error when an invalid timeout usec value is used during connect: "); @@ -1404,15 +1404,15 @@ static void test_invalid_timeout_errors(struct config config) { config.connect_timeout.tv_usec = 10000001; if (config.type == CONN_TCP || config.type == CONN_SSL) { - c = redisConnectWithTimeout(config.tcp.host, config.tcp.port, config.connect_timeout); + c = redictConnectWithTimeout(config.tcp.host, config.tcp.port, config.connect_timeout); } else if(config.type == CONN_UNIX) { - c = redisConnectUnixWithTimeout(config.unix_sock.path, config.connect_timeout); + c = redictConnectUnixWithTimeout(config.unix_sock.path, config.connect_timeout); } else { - redisTestPanic("Unknown connection type!"); + redictTestPanic("Unknown connection type!"); } - test_cond(c != NULL && c->err == REDIS_ERR_IO && strcmp(c->errstr, "Invalid timeout specified") == 0); - redisFree(c); + test_cond(c != NULL && c->err == REDICT_ERR_IO && strcmp(c->errstr, "Invalid timeout specified") == 0); + redictFree(c); test("Set error when an invalid timeout sec value is used during connect: "); @@ -1420,15 +1420,15 @@ static void test_invalid_timeout_errors(struct config config) { config.connect_timeout.tv_usec = 0; if (config.type == CONN_TCP || config.type == CONN_SSL) { - c = redisConnectWithTimeout(config.tcp.host, config.tcp.port, config.connect_timeout); + c = redictConnectWithTimeout(config.tcp.host, config.tcp.port, config.connect_timeout); } else if(config.type == CONN_UNIX) { - c = redisConnectUnixWithTimeout(config.unix_sock.path, config.connect_timeout); + c = redictConnectUnixWithTimeout(config.unix_sock.path, config.connect_timeout); } else { - redisTestPanic("Unknown connection type!"); + redictTestPanic("Unknown connection type!"); } - test_cond(c != NULL && c->err == REDIS_ERR_IO && strcmp(c->errstr, "Invalid timeout specified") == 0); - redisFree(c); + test_cond(c != NULL && c->err == REDICT_ERR_IO && strcmp(c->errstr, "Invalid timeout specified") == 0); + redictFree(c); } /* Wrap malloc to abort on failure so OOM checks don't make the test logic @@ -1444,32 +1444,32 @@ void *hi_malloc_safe(size_t size) { } static void test_throughput(struct config config) { - redisContext *c = do_connect(config); - redisReply **replies; + redictContext *c = do_connect(config); + redictReply **replies; int i, num; long long t1, t2; test("Throughput:\n"); for (i = 0; i < 500; i++) - freeReplyObject(redisCommand(c,"LPUSH mylist foo")); + freeReplyObject(redictCommand(c,"LPUSH mylist foo")); num = 1000; - replies = hi_malloc_safe(sizeof(redisReply*)*num); + replies = hi_malloc_safe(sizeof(redictReply*)*num); t1 = usec(); for (i = 0; i < num; i++) { - replies[i] = redisCommand(c,"PING"); - assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_STATUS); + replies[i] = redictCommand(c,"PING"); + assert(replies[i] != NULL && replies[i]->type == REDICT_REPLY_STATUS); } t2 = usec(); for (i = 0; i < num; i++) freeReplyObject(replies[i]); hi_free(replies); printf("\t(%dx PING: %.3fs)\n", num, (t2-t1)/1000000.0); - replies = hi_malloc_safe(sizeof(redisReply*)*num); + replies = hi_malloc_safe(sizeof(redictReply*)*num); t1 = usec(); for (i = 0; i < num; i++) { - replies[i] = redisCommand(c,"LRANGE mylist 0 499"); - assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_ARRAY); + replies[i] = redictCommand(c,"LRANGE mylist 0 499"); + assert(replies[i] != NULL && replies[i]->type == REDICT_REPLY_ARRAY); assert(replies[i] != NULL && replies[i]->elements == 500); } t2 = usec(); @@ -1477,11 +1477,11 @@ static void test_throughput(struct config config) { hi_free(replies); printf("\t(%dx LRANGE with 500 elements: %.3fs)\n", num, (t2-t1)/1000000.0); - replies = hi_malloc_safe(sizeof(redisReply*)*num); + replies = hi_malloc_safe(sizeof(redictReply*)*num); t1 = usec(); for (i = 0; i < num; i++) { - replies[i] = redisCommand(c, "INCRBY incrkey %d", 1000000); - assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_INTEGER); + replies[i] = redictCommand(c, "INCRBY incrkey %d", 1000000); + assert(replies[i] != NULL && replies[i]->type == REDICT_REPLY_INTEGER); } t2 = usec(); for (i = 0; i < num; i++) freeReplyObject(replies[i]); @@ -1489,26 +1489,26 @@ static void test_throughput(struct config config) { printf("\t(%dx INCRBY: %.3fs)\n", num, (t2-t1)/1000000.0); num = 10000; - replies = hi_malloc_safe(sizeof(redisReply*)*num); + replies = hi_malloc_safe(sizeof(redictReply*)*num); for (i = 0; i < num; i++) - redisAppendCommand(c,"PING"); + redictAppendCommand(c,"PING"); t1 = usec(); for (i = 0; i < num; i++) { - assert(redisGetReply(c, (void*)&replies[i]) == REDIS_OK); - assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_STATUS); + assert(redictGetReply(c, (void*)&replies[i]) == REDICT_OK); + assert(replies[i] != NULL && replies[i]->type == REDICT_REPLY_STATUS); } t2 = usec(); for (i = 0; i < num; i++) freeReplyObject(replies[i]); hi_free(replies); printf("\t(%dx PING (pipelined): %.3fs)\n", num, (t2-t1)/1000000.0); - replies = hi_malloc_safe(sizeof(redisReply*)*num); + replies = hi_malloc_safe(sizeof(redictReply*)*num); for (i = 0; i < num; i++) - redisAppendCommand(c,"LRANGE mylist 0 499"); + redictAppendCommand(c,"LRANGE mylist 0 499"); t1 = usec(); for (i = 0; i < num; i++) { - assert(redisGetReply(c, (void*)&replies[i]) == REDIS_OK); - assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_ARRAY); + assert(redictGetReply(c, (void*)&replies[i]) == REDICT_OK); + assert(replies[i] != NULL && replies[i]->type == REDICT_REPLY_ARRAY); assert(replies[i] != NULL && replies[i]->elements == 500); } t2 = usec(); @@ -1516,13 +1516,13 @@ static void test_throughput(struct config config) { hi_free(replies); printf("\t(%dx LRANGE with 500 elements (pipelined): %.3fs)\n", num, (t2-t1)/1000000.0); - replies = hi_malloc_safe(sizeof(redisReply*)*num); + replies = hi_malloc_safe(sizeof(redictReply*)*num); for (i = 0; i < num; i++) - redisAppendCommand(c,"INCRBY incrkey %d", 1000000); + redictAppendCommand(c,"INCRBY incrkey %d", 1000000); t1 = usec(); for (i = 0; i < num; i++) { - assert(redisGetReply(c, (void*)&replies[i]) == REDIS_OK); - assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_INTEGER); + assert(redictGetReply(c, (void*)&replies[i]) == REDICT_OK); + assert(replies[i] != NULL && replies[i]->type == REDICT_REPLY_INTEGER); } t2 = usec(); for (i = 0; i < num; i++) freeReplyObject(replies[i]); @@ -1533,14 +1533,14 @@ static void test_throughput(struct config config) { } // static long __test_callback_flags = 0; -// static void __test_callback(redisContext *c, void *privdata) { +// static void __test_callback(redictContext *c, void *privdata) { // ((void)c); // /* Shift to detect execution order */ // __test_callback_flags <<= 8; // __test_callback_flags |= (long)privdata; // } // -// static void __test_reply_callback(redisContext *c, redisReply *reply, void *privdata) { +// static void __test_reply_callback(redictContext *c, redictReply *reply, void *privdata) { // ((void)c); // /* Shift to detect execution order */ // __test_callback_flags <<= 8; @@ -1548,105 +1548,105 @@ static void test_throughput(struct config config) { // if (reply) freeReplyObject(reply); // } // -// static redisContext *__connect_nonblock() { +// static redictContext *__connect_nonblock() { // /* Reset callback flags */ // __test_callback_flags = 0; -// return redisConnectNonBlock("127.0.0.1", port, NULL); +// return redictConnectNonBlock("127.0.0.1", port, NULL); // } // // static void test_nonblocking_connection() { -// redisContext *c; +// redictContext *c; // int wdone = 0; // // test("Calls command callback when command is issued: "); // c = __connect_nonblock(); -// redisSetCommandCallback(c,__test_callback,(void*)1); -// redisCommand(c,"PING"); +// redictSetCommandCallback(c,__test_callback,(void*)1); +// redictCommand(c,"PING"); // test_cond(__test_callback_flags == 1); -// redisFree(c); +// redictFree(c); // // test("Calls disconnect callback on redictDisconnect: "); // c = __connect_nonblock(); -// redisSetDisconnectCallback(c,__test_callback,(void*)2); -// redisDisconnect(c); +// redictSetDisconnectCallback(c,__test_callback,(void*)2); +// redictDisconnect(c); // test_cond(__test_callback_flags == 2); -// redisFree(c); +// redictFree(c); // // test("Calls disconnect callback and free callback on redictFree: "); // c = __connect_nonblock(); -// redisSetDisconnectCallback(c,__test_callback,(void*)2); -// redisSetFreeCallback(c,__test_callback,(void*)4); -// redisFree(c); +// redictSetDisconnectCallback(c,__test_callback,(void*)2); +// redictSetFreeCallback(c,__test_callback,(void*)4); +// redictFree(c); // test_cond(__test_callback_flags == ((2 << 8) | 4)); // // test("redictBufferWrite against empty write buffer: "); // c = __connect_nonblock(); -// test_cond(redisBufferWrite(c,&wdone) == REDIS_OK && wdone == 1); -// redisFree(c); +// test_cond(redictBufferWrite(c,&wdone) == REDICT_OK && wdone == 1); +// redictFree(c); // // test("redictBufferWrite against not yet connected fd: "); // c = __connect_nonblock(); -// redisCommand(c,"PING"); -// test_cond(redisBufferWrite(c,NULL) == REDIS_ERR && +// redictCommand(c,"PING"); +// test_cond(redictBufferWrite(c,NULL) == REDICT_ERR && // strncmp(c->error,"write:",6) == 0); -// redisFree(c); +// redictFree(c); // // test("redictBufferWrite against closed fd: "); // c = __connect_nonblock(); -// redisCommand(c,"PING"); -// redisDisconnect(c); -// test_cond(redisBufferWrite(c,NULL) == REDIS_ERR && +// redictCommand(c,"PING"); +// redictDisconnect(c); +// test_cond(redictBufferWrite(c,NULL) == REDICT_ERR && // strncmp(c->error,"write:",6) == 0); -// redisFree(c); +// redictFree(c); // // test("Process callbacks in the right sequence: "); // c = __connect_nonblock(); -// redisCommandWithCallback(c,__test_reply_callback,(void*)1,"PING"); -// redisCommandWithCallback(c,__test_reply_callback,(void*)2,"PING"); -// redisCommandWithCallback(c,__test_reply_callback,(void*)3,"PING"); +// redictCommandWithCallback(c,__test_reply_callback,(void*)1,"PING"); +// redictCommandWithCallback(c,__test_reply_callback,(void*)2,"PING"); +// redictCommandWithCallback(c,__test_reply_callback,(void*)3,"PING"); // // /* Write output buffer */ // wdone = 0; // while(!wdone) { // usleep(500); -// redisBufferWrite(c,&wdone); +// redictBufferWrite(c,&wdone); // } // // /* Read until at least one callback is executed (the 3 replies will // * arrive in a single packet, causing all callbacks to be executed in // * a single pass). */ // while(__test_callback_flags == 0) { -// assert(redisBufferRead(c) == REDIS_OK); -// redisProcessCallbacks(c); +// assert(redictBufferRead(c) == REDICT_OK); +// redictProcessCallbacks(c); // } // test_cond(__test_callback_flags == 0x010203); -// redisFree(c); +// redictFree(c); // // test("redictDisconnect executes pending callbacks with NULL reply: "); // c = __connect_nonblock(); -// redisSetDisconnectCallback(c,__test_callback,(void*)1); -// redisCommandWithCallback(c,__test_reply_callback,(void*)2,"PING"); -// redisDisconnect(c); +// redictSetDisconnectCallback(c,__test_callback,(void*)1); +// redictCommandWithCallback(c,__test_reply_callback,(void*)2,"PING"); +// redictDisconnect(c); // test_cond(__test_callback_flags == 0x0201); -// redisFree(c); +// redictFree(c); // } -#ifdef HIREDIS_TEST_ASYNC +#ifdef HIREDICT_TEST_ASYNC #pragma GCC diagnostic ignored "-Woverlength-strings" /* required on gcc 4.8.x due to assert statements */ struct event_base *base; typedef struct TestState { - redisOptions *options; + redictOptions *options; int checkpoint; int resp3; int disconnect; } TestState; /* Helper to disconnect and stop event loop */ -void async_disconnect(redisAsyncContext *ac) { - redisAsyncDisconnect(ac); +void async_disconnect(redictAsyncContext *ac) { + redictAsyncDisconnect(ac); event_base_loopbreak(base); } @@ -1658,27 +1658,27 @@ void timeout_cb(int fd, short event, void *arg) { } /* Unexpected call, will trigger a failure */ -void unexpected_cb(redisAsyncContext *ac, void *r, void *privdata) { +void unexpected_cb(redictAsyncContext *ac, void *r, void *privdata) { (void) ac; (void) r; printf("Unexpected call: %s\n",(char*)privdata); exit(1); } /* Helper function to publish a message via own client. */ -void publish_msg(redisOptions *options, const char* channel, const char* msg) { - redisContext *c = redisConnectWithOptions(options); +void publish_msg(redictOptions *options, const char* channel, const char* msg) { + redictContext *c = redictConnectWithOptions(options); assert(c != NULL); - redisReply *reply = redisCommand(c,"PUBLISH %s %s",channel,msg); - assert(reply->type == REDIS_REPLY_INTEGER && reply->integer == 1); + redictReply *reply = redictCommand(c,"PUBLISH %s %s",channel,msg); + assert(reply->type == REDICT_REPLY_INTEGER && reply->integer == 1); freeReplyObject(reply); disconnect(c, 0); } /* Expect a reply of type INTEGER */ -void integer_cb(redisAsyncContext *ac, void *r, void *privdata) { - redisReply *reply = r; +void integer_cb(redictAsyncContext *ac, void *r, void *privdata) { + redictReply *reply = r; TestState *state = privdata; - assert(reply != NULL && reply->type == REDIS_REPLY_INTEGER); + assert(reply != NULL && reply->type == REDICT_REPLY_INTEGER); state->checkpoint++; if (state->disconnect) async_disconnect(ac); } @@ -1686,12 +1686,12 @@ void integer_cb(redisAsyncContext *ac, void *r, void *privdata) { /* Subscribe callback for test_pubsub_handling and test_pubsub_handling_resp3: * - a published message triggers an unsubscribe * - a command is sent before the unsubscribe response is received. */ -void subscribe_cb(redisAsyncContext *ac, void *r, void *privdata) { - redisReply *reply = r; +void subscribe_cb(redictAsyncContext *ac, void *r, void *privdata) { + redictReply *reply = r; TestState *state = privdata; assert(reply != NULL && - reply->type == (state->resp3 ? REDIS_REPLY_PUSH : REDIS_REPLY_ARRAY) && + reply->type == (state->resp3 ? REDICT_REPLY_PUSH : REDICT_REPLY_ARRAY) && reply->elements == 3); if (strcmp(reply->element[0]->str,"subscribe") == 0) { @@ -1705,12 +1705,12 @@ void subscribe_cb(redisAsyncContext *ac, void *r, void *privdata) { /* Unsubscribe after receiving the published message. Send unsubscribe * which should call the callback registered during subscribe */ - redisAsyncCommand(ac,unexpected_cb, + redictAsyncCommand(ac,unexpected_cb, (void*)"unsubscribe should call subscribe_cb()", "unsubscribe"); /* Send a regular command after unsubscribing, then disconnect */ state->disconnect = 1; - redisAsyncCommand(ac,integer_cb,state,"LPUSH mylist foo"); + redictAsyncCommand(ac,integer_cb,state,"LPUSH mylist foo"); } else if (strcmp(reply->element[0]->str,"unsubscribe") == 0) { assert(strcmp(reply->element[1]->str,"mychannel") == 0 && @@ -1722,16 +1722,16 @@ void subscribe_cb(redisAsyncContext *ac, void *r, void *privdata) { } /* Expect a reply of type ARRAY */ -void array_cb(redisAsyncContext *ac, void *r, void *privdata) { - redisReply *reply = r; +void array_cb(redictAsyncContext *ac, void *r, void *privdata) { + redictReply *reply = r; TestState *state = privdata; - assert(reply != NULL && reply->type == REDIS_REPLY_ARRAY); + assert(reply != NULL && reply->type == REDICT_REPLY_ARRAY); state->checkpoint++; if (state->disconnect) async_disconnect(ac); } /* Expect a NULL reply */ -void null_cb(redisAsyncContext *ac, void *r, void *privdata) { +void null_cb(redictAsyncContext *ac, void *r, void *privdata) { (void) ac; assert(r == NULL); TestState *state = privdata; @@ -1750,17 +1750,17 @@ static void test_pubsub_handling(struct config config) { evtimer_add(timeout, &timeout_tv); /* Connect */ - redisOptions options = get_redis_tcp_options(config); - redisAsyncContext *ac = redisAsyncConnectWithOptions(&options); + redictOptions options = get_redict_tcp_options(config); + redictAsyncContext *ac = redictAsyncConnectWithOptions(&options); assert(ac != NULL && ac->err == 0); - redisLibeventAttach(ac,base); + redictLibeventAttach(ac,base); /* Start subscribe */ TestState state = {.options = &options}; - redisAsyncCommand(ac,subscribe_cb,&state,"subscribe mychannel"); + redictAsyncCommand(ac,subscribe_cb,&state,"subscribe mychannel"); /* Make sure non-subscribe commands are handled */ - redisAsyncCommand(ac,array_cb,&state,"PING"); + redictAsyncCommand(ac,array_cb,&state,"PING"); /* Start event dispatching loop */ test_cond(event_base_dispatch(base) == 0); @@ -1772,7 +1772,7 @@ static void test_pubsub_handling(struct config config) { } /* Unexpected push message, will trigger a failure */ -void unexpected_push_cb(redisAsyncContext *ac, void *r) { +void unexpected_push_cb(redictAsyncContext *ac, void *r) { (void) ac; (void) r; printf("Unexpected call to the PUSH callback!\n"); exit(1); @@ -1790,27 +1790,27 @@ static void test_pubsub_handling_resp3(struct config config) { evtimer_add(timeout, &timeout_tv); /* Connect */ - redisOptions options = get_redis_tcp_options(config); - redisAsyncContext *ac = redisAsyncConnectWithOptions(&options); + redictOptions options = get_redict_tcp_options(config); + redictAsyncContext *ac = redictAsyncConnectWithOptions(&options); assert(ac != NULL && ac->err == 0); - redisLibeventAttach(ac,base); + redictLibeventAttach(ac,base); /* Not expecting any push messages in this test */ - redisAsyncSetPushCallback(ac, unexpected_push_cb); + redictAsyncSetPushCallback(ac, unexpected_push_cb); /* Switch protocol */ - redisAsyncCommand(ac,NULL,NULL,"HELLO 3"); + redictAsyncCommand(ac,NULL,NULL,"HELLO 3"); /* Start subscribe */ TestState state = {.options = &options, .resp3 = 1}; - redisAsyncCommand(ac,subscribe_cb,&state,"subscribe mychannel"); + redictAsyncCommand(ac,subscribe_cb,&state,"subscribe mychannel"); /* Make sure non-subscribe commands are handled in RESP3 */ - redisAsyncCommand(ac,integer_cb,&state,"LPUSH mylist foo"); - redisAsyncCommand(ac,integer_cb,&state,"LPUSH mylist foo"); - redisAsyncCommand(ac,integer_cb,&state,"LPUSH mylist foo"); + redictAsyncCommand(ac,integer_cb,&state,"LPUSH mylist foo"); + redictAsyncCommand(ac,integer_cb,&state,"LPUSH mylist foo"); + redictAsyncCommand(ac,integer_cb,&state,"LPUSH mylist foo"); /* Handle an array with 3 elements as a non-subscribe command */ - redisAsyncCommand(ac,array_cb,&state,"LRANGE mylist 0 2"); + redictAsyncCommand(ac,array_cb,&state,"LRANGE mylist 0 2"); /* Start event dispatching loop */ test_cond(event_base_dispatch(base) == 0); @@ -1825,8 +1825,8 @@ static void test_pubsub_handling_resp3(struct config config) { * - a subscribe response triggers a published message * - the published message triggers a command that times out * - the command timeout triggers a disconnect */ -void subscribe_with_timeout_cb(redisAsyncContext *ac, void *r, void *privdata) { - redisReply *reply = r; +void subscribe_with_timeout_cb(redictAsyncContext *ac, void *r, void *privdata) { + redictReply *reply = r; TestState *state = privdata; /* The non-clean disconnect should trigger the @@ -1837,7 +1837,7 @@ void subscribe_with_timeout_cb(redisAsyncContext *ac, void *r, void *privdata) { return; } - assert(reply->type == (state->resp3 ? REDIS_REPLY_PUSH : REDIS_REPLY_ARRAY) && + assert(reply->type == (state->resp3 ? REDICT_REPLY_PUSH : REDICT_REPLY_ARRAY) && reply->elements == 3); if (strcmp(reply->element[0]->str,"subscribe") == 0) { @@ -1851,8 +1851,8 @@ void subscribe_with_timeout_cb(redisAsyncContext *ac, void *r, void *privdata) { state->checkpoint++; /* Send a command that will trigger a timeout */ - redisAsyncCommand(ac,null_cb,state,"DEBUG SLEEP 3"); - redisAsyncCommand(ac,null_cb,state,"LPUSH mylist foo"); + redictAsyncCommand(ac,null_cb,state,"DEBUG SLEEP 3"); + redictAsyncCommand(ac,null_cb,state,"LPUSH mylist foo"); } else { printf("Unexpected pubsub command: %s\n", reply->element[0]->str); exit(1); @@ -1871,24 +1871,24 @@ static void test_command_timeout_during_pubsub(struct config config) { evtimer_add(timeout,&timeout_tv); /* Connect */ - redisOptions options = get_redis_tcp_options(config); - redisAsyncContext *ac = redisAsyncConnectWithOptions(&options); + redictOptions options = get_redict_tcp_options(config); + redictAsyncContext *ac = redictAsyncConnectWithOptions(&options); assert(ac != NULL && ac->err == 0); - redisLibeventAttach(ac,base); + redictLibeventAttach(ac,base); /* Configure a command timout */ struct timeval command_timeout = {.tv_sec = 2}; - redisAsyncSetTimeout(ac,command_timeout); + redictAsyncSetTimeout(ac,command_timeout); /* Not expecting any push messages in this test */ - redisAsyncSetPushCallback(ac,unexpected_push_cb); + redictAsyncSetPushCallback(ac,unexpected_push_cb); /* Switch protocol */ - redisAsyncCommand(ac,NULL,NULL,"HELLO 3"); + redictAsyncCommand(ac,NULL,NULL,"HELLO 3"); /* Start subscribe */ TestState state = {.options = &options, .resp3 = 1}; - redisAsyncCommand(ac,subscribe_with_timeout_cb,&state,"subscribe mychannel"); + redictAsyncCommand(ac,subscribe_with_timeout_cb,&state,"subscribe mychannel"); /* Start event dispatching loop */ assert(event_base_dispatch(base) == 0); @@ -1900,11 +1900,11 @@ static void test_command_timeout_during_pubsub(struct config config) { } /* Subscribe callback for test_pubsub_multiple_channels */ -void subscribe_channel_a_cb(redisAsyncContext *ac, void *r, void *privdata) { - redisReply *reply = r; +void subscribe_channel_a_cb(redictAsyncContext *ac, void *r, void *privdata) { + redictReply *reply = r; TestState *state = privdata; - assert(reply != NULL && reply->type == REDIS_REPLY_ARRAY && + assert(reply != NULL && reply->type == REDICT_REPLY_ARRAY && reply->elements == 3); if (strcmp(reply->element[0]->str,"subscribe") == 0) { @@ -1917,16 +1917,16 @@ void subscribe_channel_a_cb(redisAsyncContext *ac, void *r, void *privdata) { state->checkpoint++; /* Unsubscribe to channels, including channel X & Z which we don't subscribe to */ - redisAsyncCommand(ac,unexpected_cb, + redictAsyncCommand(ac,unexpected_cb, (void*)"unsubscribe should not call unexpected_cb()", "unsubscribe B X A A Z"); /* Unsubscribe to patterns, none which we subscribe to */ - redisAsyncCommand(ac,unexpected_cb, + redictAsyncCommand(ac,unexpected_cb, (void*)"punsubscribe should not call unexpected_cb()", "punsubscribe"); /* Send a regular command after unsubscribing, then disconnect */ state->disconnect = 1; - redisAsyncCommand(ac,integer_cb,state,"LPUSH mylist foo"); + redictAsyncCommand(ac,integer_cb,state,"LPUSH mylist foo"); } else if (strcmp(reply->element[0]->str,"unsubscribe") == 0) { assert(strcmp(reply->element[1]->str,"A") == 0); state->checkpoint++; @@ -1937,12 +1937,12 @@ void subscribe_channel_a_cb(redisAsyncContext *ac, void *r, void *privdata) { } /* Subscribe callback for test_pubsub_multiple_channels */ -void subscribe_channel_b_cb(redisAsyncContext *ac, void *r, void *privdata) { - redisReply *reply = r; +void subscribe_channel_b_cb(redictAsyncContext *ac, void *r, void *privdata) { + redictReply *reply = r; TestState *state = privdata; (void)ac; - assert(reply != NULL && reply->type == REDIS_REPLY_ARRAY && + assert(reply != NULL && reply->type == REDICT_REPLY_ARRAY && reply->elements == 3); if (strcmp(reply->element[0]->str,"subscribe") == 0) { @@ -1976,18 +1976,18 @@ static void test_pubsub_multiple_channels(struct config config) { evtimer_add(timeout,&timeout_tv); /* Connect */ - redisOptions options = get_redis_tcp_options(config); - redisAsyncContext *ac = redisAsyncConnectWithOptions(&options); + redictOptions options = get_redict_tcp_options(config); + redictAsyncContext *ac = redictAsyncConnectWithOptions(&options); assert(ac != NULL && ac->err == 0); - redisLibeventAttach(ac,base); + redictLibeventAttach(ac,base); /* Not expecting any push messages in this test */ - redisAsyncSetPushCallback(ac,unexpected_push_cb); + redictAsyncSetPushCallback(ac,unexpected_push_cb); /* Start subscribing to two channels */ TestState state = {.options = &options}; - redisAsyncCommand(ac,subscribe_channel_a_cb,&state,"subscribe A"); - redisAsyncCommand(ac,subscribe_channel_b_cb,&state,"subscribe B"); + redictAsyncCommand(ac,subscribe_channel_a_cb,&state,"subscribe A"); + redictAsyncCommand(ac,subscribe_channel_b_cb,&state,"subscribe B"); /* Start event dispatching loop */ assert(event_base_dispatch(base) == 0); @@ -1999,8 +1999,8 @@ static void test_pubsub_multiple_channels(struct config config) { } /* Command callback for test_monitor() */ -void monitor_cb(redisAsyncContext *ac, void *r, void *privdata) { - redisReply *reply = r; +void monitor_cb(redictAsyncContext *ac, void *r, void *privdata) { + redictReply *reply = r; TestState *state = privdata; /* NULL reply is received when BYE triggers a disconnect. */ @@ -2009,31 +2009,31 @@ void monitor_cb(redisAsyncContext *ac, void *r, void *privdata) { return; } - assert(reply != NULL && reply->type == REDIS_REPLY_STATUS); + assert(reply != NULL && reply->type == REDICT_REPLY_STATUS); state->checkpoint++; if (state->checkpoint == 1) { /* Response from MONITOR */ - redisContext *c = redisConnectWithOptions(state->options); + redictContext *c = redictConnectWithOptions(state->options); assert(c != NULL); - redisReply *reply = redisCommand(c,"SET first 1"); - assert(reply->type == REDIS_REPLY_STATUS); + redictReply *reply = redictCommand(c,"SET first 1"); + assert(reply->type == REDICT_REPLY_STATUS); freeReplyObject(reply); - redisFree(c); + redictFree(c); } else if (state->checkpoint == 2) { /* Response for monitored command 'SET first 1' */ assert(strstr(reply->str,"first") != NULL); - redisContext *c = redisConnectWithOptions(state->options); + redictContext *c = redictConnectWithOptions(state->options); assert(c != NULL); - redisReply *reply = redisCommand(c,"SET second 2"); - assert(reply->type == REDIS_REPLY_STATUS); + redictReply *reply = redictCommand(c,"SET second 2"); + assert(reply->type == REDICT_REPLY_STATUS); freeReplyObject(reply); - redisFree(c); + redictFree(c); } else if (state->checkpoint == 3) { /* Response for monitored command 'SET second 2' */ assert(strstr(reply->str,"second") != NULL); /* Send QUIT to disconnect */ - redisAsyncCommand(ac,NULL,NULL,"QUIT"); + redictAsyncCommand(ac,NULL,NULL,"QUIT"); } } @@ -2053,17 +2053,17 @@ static void test_monitor(struct config config) { evtimer_add(timeout, &timeout_tv); /* Connect */ - redisOptions options = get_redis_tcp_options(config); - redisAsyncContext *ac = redisAsyncConnectWithOptions(&options); + redictOptions options = get_redict_tcp_options(config); + redictAsyncContext *ac = redictAsyncConnectWithOptions(&options); assert(ac != NULL && ac->err == 0); - redisLibeventAttach(ac,base); + redictLibeventAttach(ac,base); /* Not expecting any push messages in this test */ - redisAsyncSetPushCallback(ac,unexpected_push_cb); + redictAsyncSetPushCallback(ac,unexpected_push_cb); /* Start monitor */ TestState state = {.options = &options}; - redisAsyncCommand(ac,monitor_cb,&state,"monitor"); + redictAsyncCommand(ac,monitor_cb,&state,"monitor"); /* Start event dispatching loop */ test_cond(event_base_dispatch(base) == 0); @@ -2073,7 +2073,7 @@ static void test_monitor(struct config config) { /* Verify test checkpoints */ assert(state.checkpoint == 3); } -#endif /* HIREDIS_TEST_ASYNC */ +#endif /* HIREDICT_TEST_ASYNC */ /* tests for async api using polling adapter, requires no extra libraries*/ @@ -2090,7 +2090,7 @@ typedef enum astest_no /* a static context for the async tests */ struct _astest { - redisAsyncContext *ac; + redictAsyncContext *ac; astest_no testno; int counter; int connects; @@ -2111,9 +2111,9 @@ static void asCleanup(void* data) t->ac = NULL; } -static void commandCallback(struct redisAsyncContext *ac, void* _reply, void* _privdata); +static void commandCallback(struct redictAsyncContext *ac, void* _reply, void* _privdata); -static void connectCallback(redisAsyncContext *c, int status) { +static void connectCallback(redictAsyncContext *c, int status) { struct _astest *t = (struct _astest *)c->data; assert(t == &astest); assert(t->connects == 0); @@ -2121,18 +2121,18 @@ static void connectCallback(redisAsyncContext *c, int status) { strcpy(t->errstr, c->errstr); t->connects++; t->connect_status = status; - t->connected = status == REDIS_OK ? 1 : -1; + t->connected = status == REDICT_OK ? 1 : -1; if (t->testno == ASTEST_ISSUE_931) { /* disconnect again */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } else if (t->testno == ASTEST_ISSUE_931_PING) { - redisAsyncCommand(c, commandCallback, NULL, "PING"); + redictAsyncCommand(c, commandCallback, NULL, "PING"); } } -static void disconnectCallback(const redisAsyncContext *c, int status) { +static void disconnectCallback(const redictAsyncContext *c, int status) { assert(c->data == (void*)&astest); assert(astest.disconnects == 0); astest.err = c->err; @@ -2142,9 +2142,9 @@ static void disconnectCallback(const redisAsyncContext *c, int status) { astest.connected = 0; } -static void commandCallback(struct redisAsyncContext *ac, void* _reply, void* _privdata) +static void commandCallback(struct redictAsyncContext *ac, void* _reply, void* _privdata) { - redisReply *reply = (redisReply*)_reply; + redictReply *reply = (redictReply*)_reply; struct _astest *t = (struct _astest *)ac->data; assert(t == &astest); (void)_privdata; @@ -2153,61 +2153,61 @@ static void commandCallback(struct redisAsyncContext *ac, void* _reply, void* _p t->counter++; if (t->testno == ASTEST_PINGPONG ||t->testno == ASTEST_ISSUE_931_PING) { - assert(reply != NULL && reply->type == REDIS_REPLY_STATUS && strcmp(reply->str, "PONG") == 0); + assert(reply != NULL && reply->type == REDICT_REPLY_STATUS && strcmp(reply->str, "PONG") == 0); t->pongs++; - redisAsyncFree(ac); + redictAsyncFree(ac); } if (t->testno == ASTEST_PINGPONG_TIMEOUT) { /* two ping pongs */ - assert(reply != NULL && reply->type == REDIS_REPLY_STATUS && strcmp(reply->str, "PONG") == 0); + assert(reply != NULL && reply->type == REDICT_REPLY_STATUS && strcmp(reply->str, "PONG") == 0); t->pongs++; if (t->counter == 1) { - int status = redisAsyncCommand(ac, commandCallback, NULL, "PING"); - assert(status == REDIS_OK); + int status = redictAsyncCommand(ac, commandCallback, NULL, "PING"); + assert(status == REDICT_OK); } else { - redisAsyncFree(ac); + redictAsyncFree(ac); } } } -static redisAsyncContext *do_aconnect(struct config config, astest_no testno) +static redictAsyncContext *do_aconnect(struct config config, astest_no testno) { - redisOptions options = {0}; + redictOptions options = {0}; memset(&astest, 0, sizeof(astest)); astest.testno = testno; astest.connect_status = astest.disconnect_status = -2; if (config.type == CONN_TCP) { - options.type = REDIS_CONN_TCP; + options.type = REDICT_CONN_TCP; options.connect_timeout = &config.connect_timeout; - REDIS_OPTIONS_SET_TCP(&options, config.tcp.host, config.tcp.port); + REDICT_OPTIONS_SET_TCP(&options, config.tcp.host, config.tcp.port); } else if (config.type == CONN_SSL) { - options.type = REDIS_CONN_TCP; + options.type = REDICT_CONN_TCP; options.connect_timeout = &config.connect_timeout; - REDIS_OPTIONS_SET_TCP(&options, config.ssl.host, config.ssl.port); + REDICT_OPTIONS_SET_TCP(&options, config.ssl.host, config.ssl.port); } else if (config.type == CONN_UNIX) { - options.type = REDIS_CONN_UNIX; + options.type = REDICT_CONN_UNIX; options.endpoint.unix_socket = config.unix_sock.path; } else if (config.type == CONN_FD) { - options.type = REDIS_CONN_USERFD; + options.type = REDICT_CONN_USERFD; /* Create a dummy connection just to get an fd to inherit */ - redisContext *dummy_ctx = redisConnectUnix(config.unix_sock.path); + redictContext *dummy_ctx = redictConnectUnix(config.unix_sock.path); if (dummy_ctx) { - redisFD fd = disconnect(dummy_ctx, 1); + redictFD fd = disconnect(dummy_ctx, 1); printf("Connecting to inherited fd %d\n", (int)fd); options.endpoint.fd = fd; } } - redisAsyncContext *c = redisAsyncConnectWithOptions(&options); + redictAsyncContext *c = redictAsyncConnectWithOptions(&options); assert(c); astest.ac = c; c->data = &astest; c->dataCleanup = asCleanup; - redisPollAttach(c); - redisAsyncSetConnectCallbackNC(c, connectCallback); - redisAsyncSetDisconnectCallback(c, disconnectCallback); + redictPollAttach(c); + redictAsyncSetConnectCallbackNC(c, connectCallback); + redictAsyncSetDisconnectCallback(c, disconnectCallback); return c; } @@ -2223,25 +2223,25 @@ static void as_printerr(void) { static void test_async_polling(struct config config) { int status; - redisAsyncContext *c; + redictAsyncContext *c; struct config defaultconfig = config; test("Async connect: "); c = do_aconnect(config, ASTEST_CONNECT); assert(c); while(astest.connected == 0) - redisPollTick(c, 0.1); + redictPollTick(c, 0.1); assert(astest.connects == 1); - ASASSERT(astest.connect_status == REDIS_OK); + ASASSERT(astest.connect_status == REDICT_OK); assert(astest.disconnects == 0); test_cond(astest.connected == 1); test("Async free after connect: "); assert(astest.ac != NULL); - redisAsyncFree(c); + redictAsyncFree(c); assert(astest.disconnects == 1); assert(astest.ac == NULL); - test_cond(astest.disconnect_status == REDIS_OK); + test_cond(astest.disconnect_status == REDICT_OK); if (config.type == CONN_TCP || config.type == CONN_SSL) { /* timeout can only be simulated with network */ @@ -2252,14 +2252,14 @@ static void test_async_polling(struct config config) { assert(c); assert(c->err == 0); while(astest.connected == 0) - redisPollTick(c, 0.1); + redictPollTick(c, 0.1); assert(astest.connected == -1); /* * freeing should not be done, clearing should have happened. - *redisAsyncFree(c); + *redictAsyncFree(c); */ assert(astest.ac == NULL); - test_cond(astest.connect_status == REDIS_ERR); + test_cond(astest.connect_status == REDICT_ERR); config = defaultconfig; } @@ -2267,51 +2267,51 @@ static void test_async_polling(struct config config) { test("Async PING/PONG: "); c = do_aconnect(config, ASTEST_PINGPONG); while(astest.connected == 0) - redisPollTick(c, 0.1); - status = redisAsyncCommand(c, commandCallback, NULL, "PING"); - assert(status == REDIS_OK); + redictPollTick(c, 0.1); + status = redictAsyncCommand(c, commandCallback, NULL, "PING"); + assert(status == REDICT_OK); while(astest.ac) - redisPollTick(c, 0.1); + redictPollTick(c, 0.1); test_cond(astest.pongs == 1); /* Test a ping/pong after connection that didn't time out. - * see https://github.com/redis/hiredis/issues/945 + * see https://github.com/redict/hiredict/issues/945 */ if (config.type == CONN_TCP || config.type == CONN_SSL) { test("Async PING/PONG after connect timeout: "); config.connect_timeout.tv_usec = 10000; /* 10ms */ c = do_aconnect(config, ASTEST_PINGPONG_TIMEOUT); while(astest.connected == 0) - redisPollTick(c, 0.1); + redictPollTick(c, 0.1); /* sleep 0.1 s, allowing old timeout to arrive */ millisleep(10); - status = redisAsyncCommand(c, commandCallback, NULL, "PING"); - assert(status == REDIS_OK); + status = redictAsyncCommand(c, commandCallback, NULL, "PING"); + assert(status == REDICT_OK); while(astest.ac) - redisPollTick(c, 0.1); + redictPollTick(c, 0.1); test_cond(astest.pongs == 2); config = defaultconfig; } /* Test disconnect from an on_connect callback - * see https://github.com/redis/hiredis/issues/931 + * see https://github.com/redict/hiredict/issues/931 */ test("Disconnect from onConnected callback (Issue #931): "); c = do_aconnect(config, ASTEST_ISSUE_931); while(astest.disconnects == 0) - redisPollTick(c, 0.1); + redictPollTick(c, 0.1); assert(astest.connected == 0); assert(astest.connects == 1); test_cond(astest.disconnects == 1); /* Test ping/pong from an on_connect callback - * see https://github.com/redis/hiredis/issues/931 + * see https://github.com/redict/hiredict/issues/931 */ test("Ping/Pong from onConnected callback (Issue #931): "); c = do_aconnect(config, ASTEST_ISSUE_931_PING); /* connect callback issues ping, response callback destroys context */ while(astest.ac) - redisPollTick(c, 0.1); + redictPollTick(c, 0.1); assert(astest.connected == 0); assert(astest.connects == 1); assert(astest.disconnects == 1); @@ -2352,7 +2352,7 @@ int main(int argc, char **argv) { test_inherit_fd = 0; } else if (argc >= 1 && !strcmp(argv[0],"--skips-as-fails")) { skips_as_fails = 1; -#ifdef HIREDIS_TEST_SSL +#ifdef HIREDICT_TEST_SSL } else if (argc >= 2 && !strcmp(argv[0],"--ssl-port")) { argv++; argc--; cfg.ssl.port = atoi(argv[0]); @@ -2418,11 +2418,11 @@ int main(int argc, char **argv) { test_skipped(); } -#ifdef HIREDIS_TEST_SSL +#ifdef HIREDICT_TEST_SSL if (cfg.ssl.port && cfg.ssl.host) { - redisInitOpenSSL(); - _ssl_ctx = redisCreateSSLContext(cfg.ssl.ca_cert, NULL, cfg.ssl.cert, cfg.ssl.key, NULL, NULL); + redictInitOpenSSL(); + _ssl_ctx = redictCreateSSLContext(cfg.ssl.ca_cert, NULL, cfg.ssl.cert, cfg.ssl.key, NULL, NULL); assert(_ssl_ctx != NULL); printf("\nTesting against SSL connection (%s:%d):\n", cfg.ssl.host, cfg.ssl.port); @@ -2435,19 +2435,19 @@ int main(int argc, char **argv) { test_append_formatted_commands(cfg); if (throughput) test_throughput(cfg); - redisFreeSSLContext(_ssl_ctx); + redictFreeSSLContext(_ssl_ctx); _ssl_ctx = NULL; } #endif -#ifdef HIREDIS_TEST_ASYNC +#ifdef HIREDICT_TEST_ASYNC cfg.type = CONN_TCP; printf("\nTesting asynchronous API against TCP connection (%s:%d):\n", cfg.tcp.host, cfg.tcp.port); cfg.type = CONN_TCP; int major; - redisContext *c = do_connect(cfg); - get_redis_version(c, &major, NULL); + redictContext *c = do_connect(cfg); + get_redict_version(c, &major, NULL); disconnect(c, 0); test_pubsub_handling(cfg); @@ -2457,7 +2457,7 @@ int main(int argc, char **argv) { test_pubsub_handling_resp3(cfg); test_command_timeout_during_pubsub(cfg); } -#endif /* HIREDIS_TEST_ASYNC */ +#endif /* HIREDICT_TEST_ASYNC */ cfg.type = CONN_TCP; printf("\nTesting asynchronous API using polling_adapter TCP (%s:%d):\n", cfg.tcp.host, cfg.tcp.port); -- cgit v1.2.3