/* Copyright (c) 2019 Marcelo Zimbres Silva (mzimbres at gmail dot com) * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "aedis.hpp" using namespace aedis; void send(std::string cmd) { net::io_context ioc; session s {ioc}; s.send(std::move(cmd)); s.run(); ioc.run(); } void rpush_ex() { std::array a {"a1", "a2", "a3"}; std::vector b {"b1" ,"b2", "b3"}; std::list c {"c1" ,"c2", "c3"}; std::set d {"d1" ,"d2", "d3"}; std::deque e {"e1" ,"e2", "e3"}; std::forward_list f {"f1" ,"f2", "f3"}; std::multiset g {"g1" ,"g2", "g3"}; std::unordered_set h {"h1" ,"h2", "h3"}; std::unordered_set i {"i1" ,"i2", "i3"}; auto s = flushall() + rpush("a", a) + lrange("a") + rpush("b", b) + lrange("b") + rpush("c", c) + lrange("c") + rpush("d", d) + lrange("d") + rpush("e", e) + lrange("e") + rpush("f", f) + lrange("f") + rpush("g", g) + lrange("g") + rpush("h", h) + lrange("h") + rpush("i", i) + lrange("i") ; send(std::move(s)); } void example1() { std::list a {"one" ,"two", "three"}; std::set b {"a" ,"b", "c"}; std::map c { {{"Name"}, {"Marcelo"}} , {{"Education"}, {"Physics"}} , {{"Job"}, {"Programmer"}}}; std::map d { {1, {"foo"}} , {2, {"bar"}} , {3, {"foobar"}} }; auto s = ping() + role() + flushall() + rpush("a", a) + lrange("a") + del("a") + multi() + rpush("b", b) + lrange("b") + del("b") + hset("c", c) + hvals("c") + zadd({"d"}, d) + zrange("d") + zrangebyscore("foo", 2, -1) + set("f", {"39"}) + incr("f") + get("f") + expire("f", 10) + publish("g", "A message") + exec() + set("h", {"h"}) + append("h", "h") + get("h") + auth("password") + bitcount("h") ; send(std::move(s)); } void example2() { net::io_context ioc; session::config cfg { { "127.0.0.1", "26377" , "127.0.0.1", "26378" , "127.0.0.1", "26379"} // Sentinel addresses , "mymaster" // Instance name , "master" // Instance role , 256 // Max pipeline size , log::level::info }; session s {ioc, cfg, "id"}; s.send(ping()); s.run(); ioc.run(); } void example3() { net::io_context ioc; session s {ioc}; s.set_on_conn_handler([]() { std::cout << "Connected" << std::endl; }); s.set_msg_handler([](auto ec, auto res) { if (ec) { std::cerr << "Error: " << ec.message() << std::endl; } std::copy( std::cbegin(res) , std::cend(res) , std::ostream_iterator(std::cout, " ")); std::cout << std::endl; }); s.send(ping()); s.run(); ioc.run(); } int main(int argc, char* argv[]) { //example1(); example2(); //example3(); //rpush_ex(); }