cpp_redis (Windows C++ Redis客户端静态库,C++11实现)源码编译及使用

简介: cpp_redis (Windows C++ Redis客户端静态库,C++11实现)源码编译及使用

一、环境准备


win7,VS2015


https://github.com/Cylix/cpp_redis   v4.3.1


https://github.com/Cylix/tacopie      v3.2.0


https://cylix.github.io/cpp_redis/html/classcpp__redis_1_1client.html


把cpp_redis和tacopie的源码下载之后,把tacopie源码解压到路径


C:\Users\Administrator\Documents\Visual Studio 2015\Projects\cpp_redis-4.3.1\tacopie\


vs2015打开cpp_redis的工程,


C:\Users\Administrator\Documents\Visual Studio 2015\Projects\cpp_redis-4.3.1\msvc15\cpp_redis.sln


debug和release分别编译,最终会生成debug和release版本的lib库:


tacopie.lib


cpp_redis.lib


两个文件都很大,分别是10MB和50MB左右。。。




二、提取出头文件和静态库文件,分别新建文件夹includes和libs


1、把C:\Users\Administrator\Documents\Visual Studio 2015\Projects\cpp_redis-4.3.1\includes\cpp_redis和C:\Users\Administrator\Documents\Visual Studio 2015\Projects\cpp_redis-4.3.1\tacopie\includes\tacopie两个文件夹都拷贝到includes


--includes


   --cpp_redis


   --tacopie


2、把debug和release的tacopie.lib和cpp_redis.lib拷贝进入libs


--libs


    --debug


            --tacopie.lib


            --cpp_redis.lib


    --release


            --tacopie.lib


            --cpp_redis.lib



三、新建win32工程,实测


测试源码主要参考了,https://github.com/Cylix/cpp_redis/tree/master/examples/cpp_redis_client.cpp


本人添加了静态库的指向和redis auth的校验


另外,VS2015工程属性,配置属性,C/C++,附加包含目录写入“..\includes”

// redisclientwin32.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <cpp_redis/cpp_redis>  
#include <iostream>  
//#include <algorithm>
//#include <iterator>
#ifdef _WIN32  
#include <Winsock2.h>  
#endif /* _WIN32 */  
#ifdef _DEBUG
#pragma comment(lib, "../libs/debug/tacopie.lib")
#pragma comment(lib, "../libs/debug/cpp_redis.lib")
#else
#pragma comment(lib, "../libs/release/tacopie.lib")
#pragma comment(lib, "../libs/release/cpp_redis.lib")
#endif
int main()
{
#ifdef _WIN32
  //! Windows netword DLL init
  WORD version = MAKEWORD(2, 2);
  WSADATA data;
  if (WSAStartup(version, &data) != 0) {
    std::cerr << "WSAStartup() failure" << std::endl;
    return -1;
  }
#endif /* _WIN32 */
  //! Enable logging
  cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);
  cpp_redis::client client;
  client.connect("172.16.6.138", 6379, [](const std::string& host, std::size_t port, cpp_redis::client::connect_state status) {
    if (status == cpp_redis::client::connect_state::dropped) {
      std::cout << "client disconnected from " << host << ":" << port << std::endl;
    }
  });
  // auth,password
  client.auth("123456", [](cpp_redis::reply& reply) {
    std::cout << "auth info: " << reply << std::endl;
    // if (reply.is_string())
    //   do_something_with_string(reply.as_string())
  });
  // same as client.send({ "SET", "hello", "42" }, ...)
  client.set("hello", "42", [](cpp_redis::reply& reply) {
    std::cout << "set hello 42: " << reply << std::endl;
    // if (reply.is_string())
    //   do_something_with_string(reply.as_string())
  });
  // same as client.send({ "DECRBY", "hello", 12 }, ...)
  client.decrby("hello", 12, [](cpp_redis::reply& reply) {
    std::cout << "decrby hello 12: " << reply << std::endl;
    // if (reply.is_integer())
    //   do_something_with_integer(reply.as_integer())
  });
  // same as client.send({ "GET", "hello" }, ...)
  client.get("hello", [](cpp_redis::reply& reply) {
    std::cout << "get hello: " << reply << std::endl;
    // if (reply.is_string())
    //   do_something_with_string(reply.as_string())
  });
  // commands are pipelined and only sent when client.commit() is called
  // client.commit();
  // synchronous commit, no timeout
  client.sync_commit();
  // synchronous commit, timeout
  // client.sync_commit(std::chrono::milliseconds(100));
#ifdef _WIN32
  WSACleanup();
#endif /* _WIN32 */
    return 0;
}

完整源码下载:https://download.csdn.net/download/libaineu2004/10290808

相关文章
|
存储 算法 C++
Windows共享文件:探秘C++实现的B树索引算法奇境
在数字化时代,Windows共享文件的高效管理至关重要。B树算法以其自平衡多路搜索特性,在文件索引与存储优化中表现出色。本文探讨B树在Windows共享文件中的应用,通过C++实现具体代码,展示其构建文件索引、优化数据存储的能力,提升文件检索效率。B树通过减少磁盘I/O操作,确保查询高效,为企业和个人提供流畅的文件共享体验。
|
9月前
|
Ubuntu API C++
C++标准库、Windows API及Ubuntu API的综合应用
总之,C++标准库、Windows API和Ubuntu API的综合应用是一项挑战性较大的任务,需要开发者具备跨平台编程的深入知识和丰富经验。通过合理的架构设计和有效的工具选择,可以在不同的操作系统平台上高效地开发和部署应用程序。
331 11
|
存储 NoSQL Redis
redis 6源码解析之 object
redis 6源码解析之 object
246 6
|
机器学习/深度学习 数据采集 人机交互
springboot+redis互联网医院智能导诊系统源码,基于医疗大模型、知识图谱、人机交互方式实现
智能导诊系统基于医疗大模型、知识图谱与人机交互技术,解决患者“知症不知病”“挂错号”等问题。通过多模态交互(语音、文字、图片等)收集病情信息,结合医学知识图谱和深度推理,实现精准的科室推荐和分级诊疗引导。系统支持基于规则模板和数据模型两种开发原理:前者依赖人工设定症状-科室规则,后者通过机器学习或深度学习分析问诊数据。其特点包括快速病情收集、智能病症关联推理、最佳就医推荐、分级导流以及与院内平台联动,提升患者就诊效率和服务体验。技术架构采用 SpringBoot+Redis+MyBatis Plus+MySQL+RocketMQ,确保高效稳定运行。
912 0
|
自然语言处理 编译器 C语言
为什么C/C++编译腰要先完成汇编
C/C++ 编译过程中先生成汇编语言是历史、技术和实践的共同选择。历史上,汇编语言作为成熟的中间表示方式,简化了工具链;技术上,分阶段编译更高效,汇编便于调试和移植;实践中,保留汇编阶段降低了复杂度,增强了可移植性和优化能力。即使在现代编译器中,汇编仍作为重要桥梁,帮助开发者更好地理解和优化代码。
为什么C/C++编译腰要先完成汇编
|
存储 算法 安全
c++模板进阶操作——非类型模板参数、模板的特化以及模板的分离编译
在 C++ 中,仿函数(Functor)是指重载了函数调用运算符()的对象。仿函数可以像普通函数一样被调用,但它们实际上是对象,可以携带状态并具有更多功能。与普通函数相比,仿函数具有更强的灵活性和可扩展性。仿函数通常通过定义一个包含operator()的类来实现。public:// 重载函数调用运算符Add add;// 创建 Add 类的对象// 使用仿函数return 0;
346 0
基于springboot+thymeleaf+Redis仿知乎网站问答项目源码
基于springboot+thymeleaf+Redis仿知乎网站问答项目源码
434 36
|
自然语言处理 编译器 Linux
告别头文件,编译效率提升 42%!C++ Modules 实战解析 | 干货推荐
本文中,阿里云智能集团开发工程师李泽政以 Alinux 为操作环境,讲解模块相比传统头文件有哪些优势,并通过若干个例子,学习如何组织一个 C++ 模块工程并使用模块封装第三方库或是改造现有的项目。
1271 56
|
人工智能 数据处理 C#
AI Dev Gallery:微软开源 Windows AI 模型本地运行工具包和示例库,助理开发者快速集成 AI 功能
微软推出的AI Dev Gallery,为Windows开发者提供开源AI工具包和示例库,支持本地运行AI模型,提升开发效率。
1123 13

热门文章

最新文章