cpp-redis / cpp_redis

C++11 Lightweight Redis client: async, thread-safe, no dependency, pipelining, multi-platform
MIT License
720 stars 199 forks source link

Nested Array Data Output Formating & Extraction #68

Closed NMS0 closed 4 years ago

NMS0 commented 4 years ago

Hello,

I am trying to format output data within the fields portion of the XADD command. With the following commands:

const std::string session_name = "Data";

    client.xadd(session_name, "*", {{"Harry", "54"}, {"Jane", "41"}, {"Laura", "25"}, 
                                    {"Nicky", "36"}, {"Kevin", "32"}}, 
                                            [](cpp_redis::reply &reply) {

    });

    client.xrange(session_name, {"-", "+", 10}, [](cpp_redis::reply &reply){

        if(reply.is_array()) {
                for(const auto key : reply.as_array()) {
                     std::cout << key << std::endl;
        }
    });

client.sync_commit();

This is the current output:

1594282837961-0Harry54Jane41Kevin32Laura25Nicky36

I want to pass this information to another application but in a format that looks like this:

1594282837961-0 Harry 54 Jane 41 Kevin 32 Laura 25 Nicky 36

I have been trying multi dimensional vector manipulations to the code as I understand that this part of the output is a nested array within the default array response from redis. Nothing is working at the moment.

Can anyone help with this please? Thanks.