我在github上clone了一个hiredis Repo(redis的C客户端代码) 我想在node addon 上使用这段代码做一些功能(原因是我需要在addon里头用到redis), 我已经好久没写C了,大多数的内容都还给老师了,好不容易成功编译出来,但是在nodejs上就不行,因为没办法链接上一个叫libhiredis.so的动态库(事实上我是不知道如何在nodejs上配置链接)。
各位高人,可以帮助下我吗?
另外贴一下代码:
#include <node.h>
#include <v8.h>
#include "hiredis.h" //这里我可以索性写一个绝对地址
using namespace v8;
Handle<Value> ValueQuene(const Arguments& args){
HandleScope scope;
redisContent *c; //由于没有链接so,所以这段是报错的,没生命
redisReply *reply; //报错not declared
const char *hostname = args[0]->IsUndefined() ? "192.168.0.147" : args[0]->StringValue() ;
const int port = args[1]->IsUndefined() ? 6379 : args[1]->NumberValue();
const struct timeval timeout = {1,500000} ;
c = redisConnectionWithTimeout(hostname,port,timeout); //报错not declared
if( c == NULL || c->err){
if(c){
printf("Connection Error %s \n",c->errstr);
redisFree(c);//报错not declared
}else{
printf("UnKnow Error \n");
}
return scope.close(Error::New("Error!!"));
}
reply = redisCommand(c,"PING");//报错not declared
char* pong = reply->str;
freeReplyObject(reply);//报错not declared
redisFree(c);//报错not declared
return scope.Close(String::NewSymbol(pong));
}
void init(Handle<Object> exports) {
exports->Set(String::NewSymbol("ValueQuene"),
FunctionTemplate::New(ValueQuene)->GetFunction());
}
NODE_MODULE(ValueQuene, init)