【1】 Windows C++ Redis客户端 cpp_redis(C++11实现)官方最新源码编译 【最后更新2018-10-31】

10 篇文章 2 订阅
7 篇文章 3 订阅

该资源本人整理制作,知识付费,请尊重劳动者的成果 

联系 我的QQ就是我的CSDN头像

友情提醒:该库必须使用Visual Studio 2015及以上版本才可以编译通过!因为用到了C++11的很多新特性。

场景:

有时候我们需要在Windows下用C++访问redis服务(不管redis服务是Windows的还是Linux的都可以)

特点:

cpp_redis需要C++11特性

代码流畅,简洁明了

后续文章:

【2】Windows C++ Redis服务端搭建与客户端开发

【3】RedisClient Redis数据浏览神器(支持对Redis数据进行界面化操作)

【4】cpp_redis hello world

【5】cpp_redis reply

【6】cpp_redis exists

【7】cpp_redis hash容器 增删改查 (以及避免死锁的解决办法)

【7-A】cpp_redis send万能指令

【8】cpp_redis hash容器 增删改查 结果赋值给本地对象

【9】cpp_redis RapidJson redis (C++对象利用Rapidjson序列化到redis与反序列化)

资源:

使用官方网站最新源码编译http://redis.io/clients    https://github.com/cylix/cpp_redis

更新:2018-09-23 (Debug | Release) * (Win32 | x64) 均可直接编译,示例代码比较全面,各种操作都有

cpp_redis_master   sln

已经编译好的调用工程

use_cpp_redis sln

编译及使用教程

Windows下cpp_redis_master编译与使用.docx (自己可以从头开始重现,方便自己学习使用)

 

百度云:

 

 

客户端代码:

#include <cpp_redis/cpp_redis>

#include <iostream>

#ifdef _WIN32
#include <Winsock2.h>
#endif /* _WIN32 */

int
main(void) {
#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::redis_client client;

  client.connect("127.0.0.1", 6379, [](cpp_redis::redis_client&) {
    std::cout << "client disconnected (disconnection handler)" << std::endl;
  });

  // 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;
}

运行效果

用户体验

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

C++程序员Carea

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值