Created
July 3, 2014 13:02
-
-
Save solisoft/b9ad974b9bbece3db00d 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 "gwan.h" // G-WAN API | |
#pragma link "hiredis" | |
#include "hiredis/hiredis.h" | |
typedef struct | |
{ | |
redisContext *rCont; | |
redisReply *rReply; | |
} data_t; | |
int main(int argc, char *argv[]) | |
{ | |
data_t **d = (data_t**)get_env(argv, US_SERVER_DATA); | |
xbuf_t *reply = get_reply(argv); | |
u64 start = getus(); | |
const char *hostname = "127.0.0.1"; | |
int port = 6379; | |
struct timeval timeout = { 1, 500000 }; // 1.5 seconds | |
if(!d[0]) // first time: persistent pointer is uninitialized | |
{ | |
d[0] = (data_t*)calloc(1, sizeof(data_t)); | |
if(!d[0]) | |
return 500; // out of memory | |
d[0]->rCont = redisConnectWithTimeout(hostname, port, timeout); | |
} | |
d[0]->rReply = redisCommand(d[0]->rCont,"PING"); | |
xbuf_xcat(get_reply(argv), "PING %s<br>", d[0]->rReply->str); | |
freeReplyObject(d[0]->rReply); | |
xbuf_xcat(get_reply(argv), "<hr>%llu µs<hr>", getus() - start); | |
return 200; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment