帮酷LOGO
  • 显示原文与译文双语对照的内容
文章标签:client library  ASIO  Boost  Redis  Boost Asio  RED  redis-cli  BASE  
Boost.asio based Redis-client library.

  • 源代码名称:redisclient
  • 源代码网址:http://www.github.com/nekipelov/redisclient
  • redisclient源代码文档
  • redisclient源代码下载
  • Git URL:
    git://www.github.com/nekipelov/redisclient.git
  • Git Clone代码到本地:
    git clone http://www.github.com/nekipelov/redisclient
  • Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/nekipelov/redisclient
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
  • redisclient

    生成主状态:Build travis statusBuild appveyor status

    构建开发状态:Build travis statusBuild appveyor status

    当前版本:1.0.0.

    基于 Boost.asio的redis客户端头文件库。 简单但健壮。

    这里版本需要С++11编译器。 如果要将这里库与旧编译器一起使用,请使用版本 0.4: https://github.com/nekipelov/redisclient/tree/v0.4

    有合并源。请参阅 amalgamated 目录中的文件。

    获取/设置示例:

    #include<string>#include<vector>#include<iostream>#include<boost/asio/io_service.hpp>#include<boost/asio/ip/address.hpp>#include<redisclient/redissyncclient.h>intmain(int, char **)
    {
     boost::asio::ip::address address = boost::asio::ip::address::from_string("127.0.0.1");
     constunsignedshort port = 6379;
     boost::asio::ip::tcp::endpoint endpoint(address, port);
     boost::asio::io_service ioService;
     redisclient::RedisSyncClient redis(ioService);
     boost::system::error_code ec;
     redis.connect(endpoint, ec);
     if(ec)
     {
     std::cerr <<"Can't connect to redis: " <<ec.message() <<std::endl;
     return EXIT_FAILURE;
     }
     redisclient::RedisValue result;
     result = redis.command("SET", {"key", "value"});
     if( result.isError() )
     {
     std::cerr <<"SET error: " <<result.toString() <<"n";
     return EXIT_FAILURE;
     }
     result = redis.command("GET", {"key"});
     if( result.isOk() )
     {
     std::cout <<"GET: " <<result.toString() <<"n";
     return EXIT_SUCCESS;
     }
     else {
     std::cerr <<"GET error: " <<result.toString() <<"n";
     return EXIT_FAILURE;
     }
    }

    异步获取/设置示例:

    #include<string>#include<iostream>#include<functional>#include<boost/asio/io_service.hpp>#include<boost/asio/ip/address.hpp>#include<redisclient/redisasyncclient.h>staticconst std::string redisKey = "unique-redis-key-example";staticconst std::string redisValue = "unique-redis-value";voidhandleConnected(boost::asio::io_service &ioService, redisclient::RedisAsyncClient &redis,
     boost::system::error_code ec)
    {
     if(!ec )
     {
     redis.command("SET", {redisKey, redisValue}, [&](const redisclient::RedisValue &v) {
     std::cerr <<"SET: " <<v.toString() <<std::endl;
     redis.command("GET", {redisKey}, [&](const redisclient::RedisValue &v) {
     std::cerr <<"GET: " <<v.toString() <<std::endl;
     redis.command("DEL", {redisKey}, [&](const redisclient::RedisValue &) {
     ioService.stop();
     });
     });
     });
     }
     else {
     std::cerr <<"Can't connect to redis: " <<ec.message() <<std::endl;
     }
    }intmain(int, char **)
    {
     boost::asio::ip::address address = boost::asio::ip::address::from_string("127.0.0.1");
     constunsignedshort port = 6379;
     boost::asio::ip::tcp::endpoint endpoint(address, port);
     boost::asio::io_service ioService;
     redisclient::RedisAsyncClient redis(ioService);
     redis.connect(endpoint,
     std::bind(&handleConnected, std::ref(ioService), std::ref(redis),
     std::placeholders::_1));
     ioService.run();
     return0;
    }

    也可以像共享库一样构建库。 只需使用-DREDIS_CLIENT_DYNLIB和-DREDIS_CLIENT_BUILD构建redisclient和-DREDIS_CLIENT_DYNLIB来构建项目。



    文章标签:BASE  BOO  RED  Redis  client library  redis-cli  Boost  ASIO  

    Copyright © 2011 HelpLib All rights reserved.    知识分享协议 京ICP备05059198号-3  |  如果智培  |  酷兔英语