hiredis安装及测试

 
 
 
(3) hiredis安装 我是把libhiredis.so放到/usr/local/lib/中,把hiredis.h放到/usr/local/inlcude/hiredis/中的
 
(4) redis启动关闭 
 
    服务启动:redis-server   

    客户端连接:redis-cli

    客户端关闭:redis-cli shutdown
 
(5) hiredis测试:
 1 #include <stdio.h> 
 2 #include <hiredis/hiredis.h> 
 3 int main() 
 4 { 
 5      redisContext *conn  = redisConnect("127.0.0.1",6379); 
 6      if(conn != NULL && conn->err) 
 7      {   
 8          printf("connection error: %s\n",conn->errstr); 
 9          return 0; 
10      }   
11      redisReply *reply = (redisReply*)redisCommand(conn,"set foo 1234"); 
12      freeReplyObject(reply); 
13              
14      reply = redisCommand(conn,"get foo"); 
15      printf("%s\n",reply->str); 
16      freeReplyObject(reply); 
17              
18      redisFree(conn); 
19      return 0; 
20 }

编译命令:gcc -o  redis_test redis_test.c -L/usr/local/lib/ -lhiredis


 

 

posted @ 2013-07-02 17:12  lpshou  阅读(18633)  评论(0编辑  收藏  举报