<commit_before>redisclient
===========

Build status: [![Build Status](https://travis-ci.org/nekipelov/redisclient.svg?branch=unstable)](https://travis-ci.org/nekipelov/redisclient)

Current version: 0.4.0

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.
<commit_msg>README.md updated<commit_after>redisclient
===========

Build status: [![Build Status](https://travis-ci.org/nekipelov/redisclient.svg?branch=unstable)](https://travis-ci.org/nekipelov/redisclient)

Current version: 0.4.0

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

Get/set example:

    #include <redisclient/redissyncclient.h>
    
    int main(int, char **)
    {
        boost::asio::ip::address address = boost::asio::ip::address::from_string("127.0.0.1");
        const unsigned short port = 6379;
    
        boost::asio::io_service ioService;
        RedisSyncClient redis(ioService);
        std::string errmsg;

        if( !redis.connect(address, port, errmsg) )
        {
            std::cerr << "Can't connect to redis: " << errmsg << std::endl;
            return EXIT_FAILURE;
        }
    
        const std::string key = "unique-redis-key-example";
        const char value [] = "unique-redis-value";
    
        redis.command("SET", key, value);
        RedisValue result = redis.command("GET", key);
    
        std::cout << "SET " << key << ": " << value << "\n";
        std::cout << "GET " << key << ": " << result.toString() << "\n";
        
        return EXIT_SUCCESS;
    }

Async get/set example:

    #include <redisclient/redisasyncclient.h>
    
    static const std::string redisKey = "unique-redis-key-example";
    static const std::string redisValue = "unique-redis-value";
    
    void handleConnected(boost::asio::io_service &ioService, RedisAsyncClient &redis,
            bool ok, const std::string &errmsg)
    {
        if( ok )
        {
            redis.command("SET", redisKey, redisValue, [&](const RedisValue &v) {
                std::cerr << "SET: " << v.toString() << std::endl;

                redis.command("GET", redisKey, [&](const RedisValue &v) {
                    std::cerr << "GET: " << v.toString() << std::endl;
    
                    redis.command("DEL", redisKey, [&](const RedisValue &) {
                        ioService.stop();
                    });
                });
            });
        }
        else
        {
            std::cerr << "Can't connect to redis: " << errmsg << std::endl;
        }
    }
    
    int main(int, char **)
    {
        boost::asio::ip::address address = boost::asio::ip::address::from_string("127.0.0.1");
        const unsigned short port = 6379;
    
        boost::asio::io_service ioService;
        RedisAsyncClient redis(ioService);

        redis.asyncConnect(address, port,
                boost::bind(&handleConnected, boost::ref(ioService), boost::ref(redis), _1, _2));
    
        ioService.run();
    
        return 0;
    }


    
Publish/subscribe example:

    #include <redisclient/redisasyncclient.h>
    
    static const std::string channelName = "unique-redis-channel-name-example";
    
    void subscribeHandler(boost::asio::io_service &ioService, const std::vector<char> &buf)
    {
        std::string msg(buf.begin(), buf.end());
    
        if( msg == "stop" )
            ioService.stop();
    }
    
    void publishHandler(RedisAsyncClient &publisher, const RedisValue &)
    {
        publisher.publish(channelName, "First hello", [&](const RedisValue &) {
            publisher.publish(channelName, "Last hello", [&](const RedisValue &) {
                publisher.publish(channelName, "stop");
            });
        });
    }
    
    int main(int, char **)
    {
        boost::asio::ip::address address = boost::asio::ip::address::from_string("127.0.0.1");
        const unsigned short port = 6379;
    
        boost::asio::io_service ioService;
        RedisAsyncClient publisher(ioService);
        RedisAsyncClient subscriber(ioService);
    
        publisher.asyncConnect(address, port, [&](bool status, const std::string &err)
        {
            if( !status )
            {
                std::cerr << "Can't connect to to redis" << err << std::endl;
            }
            else
            {
                subscriber.asyncConnect(address, port, [&](bool status, const std::string &err)
                {
                    if( !status )
                    {
                        std::cerr << "Can't connect to to redis" << err << std::endl;
                    }
                    else
                    {
                        subscriber.subscribe(channelName,
                                boost::bind(&subscribeHandler, boost::ref(ioService), _1),
                                boost::bind(&publishHandler, boost::ref(publisher), _1));
                    }
                });
            }
        });
    
        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.

{'fraction_non_alphanumeric': 0.13981358189081225, 'fraction_numerical': 0.008521970705725699, 'mean_word_length': 1.9454901960784314, 'pattern_counts': {'":': 2, '<': 89, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4166223', 'n_tokens_mistral': 2331, 'n_tokens_neox': 2236, 'n_words': 462}