summaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test.c')
-rw-r--r--test.c1440
1 files changed, 720 insertions, 720 deletions
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 <event2/event.h>
#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);