Skip to content

Instantly share code, notes, and snippets.

@solisoft
Created July 3, 2014 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solisoft/b9ad974b9bbece3db00d to your computer and use it in GitHub Desktop.
Save solisoft/b9ad974b9bbece3db00d to your computer and use it in GitHub Desktop.
#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