项目作者: aileshe

项目描述 :
simple-redis 简单的Redis C++封装类
高级语言: C++
项目地址: git://github.com/aileshe/simple-redis.git
创建时间: 2018-10-11T14:39:27Z
项目社区:https://github.com/aileshe/simple-redis

开源协议:

关键词:
cpp cpp11 redis

下载


simple-redis

simple-redis 简单的Redis C++封装类

下载安装:

  1. git clone https://github.com/aileshe/simple-redis.git

使用 DEMO:

  1. #include <iostream>
  2. #include <memory>
  3. #include "SimpleRedis.hpp"
  4. using namespace std;
  5. int main(int argc, char **argv)
  6. {
  7. try
  8. {
  9. unique_ptr<SimpleRedis> redis(new SimpleRedis);
  10. redisReply* reply = NULL;
  11. /* PING server */
  12. reply = redis->exec("PING");
  13. cout << reply->str << endl;
  14. /* Set a key */
  15. reply = redis->exec("SET %s %s", "food", "hello word!");
  16. cout << reply->str << endl;
  17. /* Get key */
  18. reply = redis->exec("GET %s", "food");
  19. cout << reply->str << endl;
  20. /* 发布与订阅 (pub/sub) */
  21. // 测试发布: > publish _TEST_ "hi Dejan!"
  22. reply = redis->exec("subscribe _TEST_");
  23. redis->freeReply();
  24. while (redisGetReply(redis->get(), (void **)&reply) == REDIS_OK)
  25. {
  26. if (NULL == reply) return 0;
  27. if (reply->type == REDIS_REPLY_ARRAY)
  28. {
  29. for (int i = 0; i < reply->elements; i++)
  30. {
  31. printf("[%d] => %s \n", i, reply->element[i]->str);
  32. }
  33. }
  34. }
  35. // 无需做任何清理... 就这么简单!! -- Dejan
  36. }
  37. catch (exception& e)
  38. {
  39. cout << e.what() << endl;
  40. }
  41. return 0;
  42. }
  43. // Linux 下编译:
  44. // g++ main.cpp SimpleRedis.cpp -I ./ -I /usr/local/include/hiredis/ -l hiredis -std=c++11

联系方式

Author: Dejan

QQ: 673008865