Skip to content

linux-fan-dave/redisclient

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redisclient

Build status: Build Status

Current version: 0.3.2

Boost.asio based Redis-client header-only library. Simple but powerfull.

Get/set example:

#include "redisclient.h"

static const std::string redisKey = "unique-redis-key-example";
static const std::string redisValue = "unique-redis-value";

int main(int, char **)
{
    const char *address = "127.0.0.1";
    const int port = 6379;

    boost::asio::io_service ioService;
    RedisClient redis(ioService);

    if( !redis.connect(address, port) )
    {
        std::cerr << "Can't connecto to redis" << std::endl;
        return EXIT_FAILURE;
    }

    redis.command("SET", redisKey, redisValue, [&](const Value &v) {
        std::cerr << "SET: " << v.toString() << std::endl;

        redis.command("GET", redisKey, [&](const Value &v) {
            std::cerr << "GET: " << v.toString() << std::endl;

            redis.command("DEL", redisKey, [&](const Value &v) {
                ioService.stop();
            });
        });
    });

    ioService.run();

    return 0;
}

Publish/subscribe example:

#include "redisclient.h"

static const std::string channelName = "unique-redis-channel-name-example";

int main(int, char **)
{
    const char *address = "127.0.0.1";
    const int port = 6379;

    boost::asio::io_service ioService;
    RedisClient publisher(ioService);
    RedisClient subscriber(ioService);

    if( !publisher.connect(address, port) || !subscriber.connect(address, port) )
    {
        std::cerr << "Can't connecto to redis" << std::endl;
        return EXIT_FAILURE;
    }

    subscriber.subscribe(channelName, [&](const std::string &msg) {
        std::cerr << "Message: " << msg << std::endl;

        if( msg == "stop" )
            ioService.stop();
    });

    publisher.publish(channelName, "First hello", [&](const Value &) {
        publisher.publish(channelName, "Last hello", [&](const Value &) {
            publisher.publish(channelName, "stop");
        });
    });

    ioService.run();

    return 0;
}

Also you can build the library like a shared library. Just use -DREDIS_CLIENT_DYNLIB and -DREDIS_CLIENT_BUILD to build redisclient and -DREDIS_CLIENT_DYNLIB to build your project.

About

Boost.asio based Redis-client library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 94.7%
  • Makefile 3.6%
  • C 1.7%