diff options
Diffstat (limited to 'examples/example.c')
-rw-r--r-- | examples/example.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/examples/example.c b/examples/example.c index 41c8189..28e77e4 100644 --- a/examples/example.c +++ b/examples/example.c @@ -13,10 +13,10 @@ #include <winsock2.h> /* For struct timeval */ #endif -static void example_argv_command(redisContext *c, size_t n) { +static void example_argv_command(redictContext *c, size_t n) { char **argv, tmp[42]; size_t *argvlen; - redisReply *reply; + redictReply *reply; /* We're allocating two additional elements for command and key */ argv = malloc(sizeof(*argv) * (2 + n)); @@ -36,17 +36,17 @@ static void example_argv_command(redisContext *c, size_t n) { argv[i] = strdup(tmp); } - /* Execute the command using redisCommandArgv. We're sending the arguments with + /* Execute the command using redictCommandArgv. We're sending the arguments with * two explicit arrays. One for each argument's string, and the other for its * length. */ - reply = redisCommandArgv(c, n + 2, (const char **)argv, (const size_t*)argvlen); + reply = redictCommandArgv(c, n + 2, (const char **)argv, (const size_t*)argvlen); if (reply == NULL || c->err) { fprintf(stderr, "Error: Couldn't execute redictCommandArgv\n"); exit(1); } - if (reply->type == REDIS_REPLY_INTEGER) { + if (reply->type == REDICT_REPLY_INTEGER) { printf("%s reply: %lld\n", argv[0], reply->integer); } @@ -63,8 +63,8 @@ static void example_argv_command(redisContext *c, size_t n) { int main(int argc, char **argv) { unsigned int j, isunix = 0; - redisContext *c; - redisReply *reply; + redictContext *c; + redictReply *reply; const char *hostname = (argc > 1) ? argv[1] : "127.0.0.1"; if (argc > 2) { @@ -79,14 +79,14 @@ int main(int argc, char **argv) { struct timeval timeout = { 1, 500000 }; // 1.5 seconds if (isunix) { - c = redisConnectUnixWithTimeout(hostname, timeout); + c = redictConnectUnixWithTimeout(hostname, timeout); } else { - c = redisConnectWithTimeout(hostname, port, timeout); + c = redictConnectWithTimeout(hostname, port, timeout); } if (c == NULL || c->err) { if (c) { printf("Connection error: %s\n", c->errstr); - redisFree(c); + redictFree(c); } else { printf("Connection error: can't allocate redict context\n"); } @@ -94,58 +94,58 @@ int main(int argc, char **argv) { } /* PING server */ - reply = redisCommand(c,"PING"); + reply = redictCommand(c,"PING"); printf("PING: %s\n", reply->str); freeReplyObject(reply); /* Set a key */ - reply = redisCommand(c,"SET %s %s", "foo", "hello world"); + reply = redictCommand(c,"SET %s %s", "foo", "hello world"); printf("SET: %s\n", reply->str); freeReplyObject(reply); /* Set a key using binary safe API */ - reply = redisCommand(c,"SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5); + reply = redictCommand(c,"SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5); printf("SET (binary API): %s\n", reply->str); freeReplyObject(reply); /* Try a GET and two INCR */ - reply = redisCommand(c,"GET foo"); + reply = redictCommand(c,"GET foo"); printf("GET foo: %s\n", reply->str); freeReplyObject(reply); - reply = redisCommand(c,"INCR counter"); + reply = redictCommand(c,"INCR counter"); printf("INCR counter: %lld\n", reply->integer); freeReplyObject(reply); /* again ... */ - reply = redisCommand(c,"INCR counter"); + reply = redictCommand(c,"INCR counter"); printf("INCR counter: %lld\n", reply->integer); freeReplyObject(reply); /* Create a list of numbers, from 0 to 9 */ - reply = redisCommand(c,"DEL mylist"); + reply = redictCommand(c,"DEL mylist"); freeReplyObject(reply); for (j = 0; j < 10; j++) { char buf[64]; snprintf(buf,64,"%u",j); - reply = redisCommand(c,"LPUSH mylist element-%s", buf); + reply = redictCommand(c,"LPUSH mylist element-%s", buf); freeReplyObject(reply); } /* Let's check what we have inside the list */ - reply = redisCommand(c,"LRANGE mylist 0 -1"); - if (reply->type == REDIS_REPLY_ARRAY) { + reply = redictCommand(c,"LRANGE mylist 0 -1"); + if (reply->type == REDICT_REPLY_ARRAY) { for (j = 0; j < reply->elements; j++) { printf("%u) %s\n", j, reply->element[j]->str); } } freeReplyObject(reply); - /* See function for an example of redisCommandArgv */ + /* See function for an example of redictCommandArgv */ example_argv_command(c, 10); /* Disconnects and frees the context */ - redisFree(c); + redictFree(c); return 0; } |