hiredis 安装和测试

首先去github下载源码,地址如下:https://github.com/redis/hiredis,该网页下包括函数详细说明

安装:

$unzip hiredis-master.zip

$cd hiredis-master

$make 

$make install


编写测试代码 connect.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "hiredis.h"

int main(void) {
	redisReply *reply;
	long int i;

//      Start measuring time
	clock_t start = clock();

//      For local connections:
	redisContext *c = redisConnect("127.0.0.1", 6379);
//      For connections to a remote Redis server:
//	redisContext *c = redisConnect
//                 ("ec2-**-**-***-**.compute-1.amazonaws.com", 6379);
	if (c->err) {
        	printf("Error: %s\n", c->errstr);
    	}else{
        	printf("Connection Made! \n");
    	}
//	Get all keys for testing
	reply = redisCommand(c, "keys %s", "*");
	if ( reply->type == REDIS_REPLY_ERROR )
  		printf( "Error: %s\n", reply->str );
	else if ( reply->type != REDIS_REPLY_ARRAY )
  		printf( "Unexpected type: %d\n", reply->type );
	else {
  		for ( i=0; i<reply->elements; ++i ){
    		   printf( "Result:%lu: %s\n", i,
                      reply->element[i]->str );
  		}
	}
	printf( "Total Number of Results: %lu\n", i );

//      Output Elapsed time
        printf ( "%f Seconds\n", ( (double)clock() - start ) /
                      CLOCKS_PER_SEC );

	freeReplyObject(reply);
}

编译,运行

$gcc -o connect connect.c libhiredis.a

$./conncet


参考资料:http://blog.csdn.net/wenchao126/article/details/8015957

该资料包括解决“libhiredis.so.0.10: cannot open shared object file”的问题


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值