Last active
March 24, 2018 09:08
-
-
Save siscia/874997263c83d44ac0ced4153909c167 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include "hiredis.h" | |
| int main() { | |
| redisContext *c; | |
| redisReply *reply; | |
| const char *hostname = "127.0.0.1"; | |
| int port = 6379; | |
| c = redisConnect(hostname, port); | |
| if (c == NULL || c->err) { | |
| if (c) { | |
| printf("Connection error: %s\n", c->errstr); | |
| redisFree(c); | |
| } else { | |
| printf("Connection error: can't allocate redis context\n"); | |
| } | |
| exit(1); | |
| } | |
| reply = redisCommand(c, "PING"); | |
| printf("PING: %s\n", reply->str); | |
| freeReplyObject(reply); | |
| reply = redisCommand(c, "REDISQL.CREATE_DB DB"); | |
| printf("CREATE_DB: %s\n", reply->str); | |
| freeReplyObject(reply); | |
| const char* create_table[] = {"REDISQL.EXEC", "DB", "CREATE TABLE test(a INT, b TEXT);"}; | |
| reply = redisCommandArgv(c, 3, create_table, NULL); | |
| printf("EXEC create table: %s\n", reply->str); | |
| freeReplyObject(reply); | |
| const char* insert_values[] = {"REDISQL.EXEC", "DB", "INSERT INTO test VALUES(1, 'foobar');"}; | |
| reply = redisCommandArgv(c, 3, insert_values, NULL); | |
| printf("EXEC insert values: %s\n", reply->str); | |
| freeReplyObject(reply); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment