-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
boost.redis #187
Comments
Hi @zxyAcmen, here is a complete example (notice I am passing #include <boost/redis/connection.hpp>
#include <boost/asio/deferred.hpp>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/consign.hpp>
#include <iostream>
#include <boost/redis/src.hpp>
namespace asio = boost::asio;
using boost::redis::config;
using boost::redis::connection;
using boost::redis::logger;
using boost::redis::request;
using boost::redis::response;
auto co_main(config cfg) -> asio::awaitable<void>
{
auto conn = std::make_shared<connection>(co_await asio::this_coro::executor);
conn->async_run(cfg, {logger::level::debug}, asio::consign(asio::detached, conn));
// 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;
}
auto main(int argc, char * argv[]) -> int
{
try {
config cfg;
asio::io_context ioc;
asio::co_spawn(ioc, co_main(cfg), [](std::exception_ptr p) {
if (p)
std::rethrow_exception(p);
});
ioc.run();
} catch (std::exception const& e) {
std::cerr << "(main) " << e.what() << std::endl;
return 1;
}
} |
@zxyAcmen I tried your sample code and the PING command does not seem to work (the sync example works fine). I can ping the test server using the redis-cli command. What do I miss?
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#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");
}
auto main(int argc, char * argv[]) -> int
{
try {
config cfg;
} 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]
Can you provide a complete example? This would be a very friendly way for new users of the boost library? thanks
The text was updated successfully, but these errors were encountered: