标签:obj oca set https test connect man redis学习 lib
一. hiredis下载地址及C API github下载:https://github.com/redis/hiredis
安装脚本:
1 #!/bin/zsh 2 git clone https://github.com/redis/hiredis.git 3 cd hiredis 4 make 5 make install
二. 文件pc,我是把libhiredis.so放到/usr/local/lib/中,把hiredis.h放到/usr/local/inlcude/hiredis/中的。
三. redis启动关闭
客户端连接:redis-cli
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
标签:obj oca set https test connect man redis学习 lib
原文地址:http://www.cnblogs.com/jikexianfeng/p/6881736.html