• hiredis在vs2010上编译不通过及解决方法


    下载源代码
    https://github.com/redis/hiredis
    然后单独创建pro文件,将相应的.c和.h文件加进去。
    然后使用vs2010(带有qt插件)打开.pro文件,编译报错
    在这里插入图片描述
    在这里插入图片描述
    上面的为C99语法,而vs2010不支持。只能选择
    https://github.com/microsoft/hiredis(c++11,vs2010不支持)
    或者https://github.com/microsoftarchive/redis2.6分支

    使用https://github.com/microsoftarchive/redis 2.6

    使用vs2010打开RedisServer.sln,同时添加win32fixes.c,win32fixes.h文件到hiredis项目中
    在这里插入图片描述
    右键点"重新生成"会生成hiredis.lib库
    在这里插入图片描述
    新建工程,设置并文件目录以及库目录
    在这里插入图片描述
    在这里插入图片描述

    在这里插入图片描述
    引入头文件

    extern "C" {
    	#include "../../src/win32fixes.h"
    }
    
    • 1
    • 2
    • 3

    测试代码

    	w32initWinSock();
    	redisContext *connect_context_;
    	redisReply *reply;
    	struct timeval timeout = {1, 500000};
    	connect_context_ = redisConnectWithTimeout((char*)"127.0.0.1", 6379, timeout);
    	if (connect_context_->err) {
    		printf("Connection error: %s\n", connect_context_->errstr);
    		exit(1);
    	}
    
    	reply = (redisReply *)redisCommand(connect_context_, "PING");
    	printf("PING: %s\n", reply->str);
    	freeReplyObject(reply);
    	
    	std::string strCmd = "set test1 Test1";
    	{
    		redisReply* r = (redisReply*)redisCommand(connect_context_, strCmd.c_str());
    		if (NULL == r)
    		{
    			printf("Execut command1 failure\n");
    			return REDIS_ERR;
    		}
    		if (!(r->type == REDIS_REPLY_STATUS && (strcmp(r->str, "OK") == 0 || strcmp(r->str, "ok") == 0)))
    		{
    			printf("Failed to execute command[%s]\n", strCmd.c_str());
    			freeReplyObject(r);
    			return REDIS_ERR;
    		}
    		freeReplyObject(r);
    		printf("Succeed to execute command[%s]\n", strCmd.c_str());
    	}
    
    	//取值
    	strCmd = "get test1";
    	{
    		redisReply* r = (redisReply*)redisCommand(connect_context_, strCmd.c_str());
    		if (NULL == r)
    		{
    			printf("Execut command1 failure\n");
    			return REDIS_ERR;
    		}
    		if (r->type != REDIS_REPLY_STRING)
    		{
    			printf("Failed to execute command[%s]\n", strCmd.c_str());
    			freeReplyObject(r);
    			return REDIS_ERR;
    		}
    		std::string strTemp = r->str;
    		freeReplyObject(r);
    		printf("Succeed to execute command[%s], value = %s\n", strCmd.c_str(), strTemp.c_str());
    	}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
  • 相关阅读:
    Ubuntu SecureCRT 菜单栏找不到后
    gitlab对/api/v4/可泄露敏感信息处理
    Mysql 如何模糊匹配后匹配优化
    微信小程序开发之路⑥
    02excel基础及函数
    SQL Serve---嵌套查询
    19 数据中心详解
    开源国内镜像站 操作系统、中间件、开发环境
    案例实践丨基于SkyWalking全链路监控的微服务系统性能调优实践篇
    Tmall商城订单管理模块分析
  • 原文地址:https://blog.csdn.net/wuli2496/article/details/132875543