简体   繁体   中英

Can't get redis connector to work with g-wan

Did all the hiredis installation defaulting to make make install etc

Result running g-wan: Linking hellox.c: undefined symbol: redisConnect

online says linking lib is wrong? how to fix this?

Read how to link libraries with G-WAN . Even with GCC you need to tell the linker what library is in use. G-WAN is not different.

Here my script working on my server :

#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;
}

You have to get hiredis compiled and copied into your lib directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM