标签:文件 .com bsp reply lib div hub context 链接
下载 redis 文件, 进行编译
wget https://github.com/redis/hiredis/archive/master.zip
将其解压, 并编译
unzip -x master.zip
make && make install
testredis.c
#include <stdio.h>
#include <stdlib.h>
#include <hiredis/hiredis.h>
/*
* 请求 redis网络缓存服务器内存.
*/
int main(int argc, char* argv[]) {
redisContext *conn = redisConnect("127.0.0.1", 6379);
if(NULL == conn) {
fprintf(stderr, "redisConnect 127.0.0.1:6379 error!\n");
exit(EXIT_FAILURE);
}
if(conn->err) {
fprintf(stderr, "redisConect error:%d\n", conn->err);
redisFree(conn);
exit(EXIT_FAILURE);
}
// 这里redisConnect 链接对象创建完毕了
redisReply *reply = redisCommand(conn, "get foo");
if(reply && reply->type == REDIS_REPLY_STRING) {
printf("get foo => %s\n", reply->str);
}
printf("reply->type = %d\n", reply->type);
// 释放这个对象
freeReplyObject(reply);
// 释放hiredis 上下文对象
redisFree(conn);
return 0;
}
make && ./testredis
查看结果;
标签:文件 .com bsp reply lib div hub context 链接
原文地址:http://www.cnblogs.com/vagabond/p/6219744.html