Skip to content

boost.redis  #187

Open
Open
@zxyAcmen

Description

@zxyAcmen

#include
#include

#include "json/json.h"

#include "boost/redis/src.hpp"
// #include <boost/lexical_cast.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/shared_mutex.hpp>

#include <boost/redis/connection.hpp>
#include <boost/redis/config.hpp>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/use_awaitable.hpp>
#include <boost/asio/io_context.hpp>

#include <boost/asio/deferred.hpp>

#include <boost/asio/detached.hpp>
#include <boost/asio/consign.hpp>
// #include

namespace asio = boost::asio;
using boost::redis::config;
using boost::redis::logger;
using boost::redis::connection;
using boost::redis::request;
using boost::redis::response;

asio::awaitable co_main(config cfg)
{
auto conn = std::make_shared(co_await asio::this_coro::executor);
conn->async_run(cfg, {}, asio::consign(asio::detached, conn));
std::cout << "host:===============" << std::endl;
// A request containing only a ping command.
request req;
req.push("PING", "Hello world");

// Response where the PONG response will be stored.
response<std::string> resp;

// Executes the request.
co_await conn->async_exec(req, resp, asio::deferred);
conn->cancel();

std::cout << "PING: " << std::get<0>(resp).value() << std::endl;
sleep(1000*1000*1000);

}

auto main(int argc, char * argv[]) -> int
{

try {
config cfg;

if (argc == 5) {
    cfg.addr.host = argv[1];
    cfg.addr.port = argv[2];
    // cfg.username = argv[3];
    cfg.password = argv[4];
    cfg.use_ssl = true;
}
std::cout << "host: " << cfg.addr.host 
    << "port: " << cfg.addr.port
    << "name: " << cfg.username 
    << "passwd: " << cfg.password
<< std::endl;
asio::io_context ioc;
asio::co_spawn(ioc, co_main(cfg), [](std::exception_ptr p) {
    if (p) {
        std::rethrow_exception(p);
    }
});
ioc.run();
sleep(1000*1000*1000);

} catch (std::exception const& e) {
std::cerr << "(main)== " << e.what() << std::endl;
return 1;
}
}

This problem has been consistently occurring

(main)== Operation canceled [system:125]
image

Can you provide a complete example? This would be a very friendly way for new users of the boost library? thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions