2
0
mirror of https://github.com/boostorg/redis.git synced 2026-02-09 11:22:22 +00:00
2020-11-15 18:03:56 +01:00
2020-09-19 10:55:46 +02:00
2020-11-15 18:03:56 +01:00
2020-09-19 10:55:46 +02:00
2020-11-15 18:03:56 +01:00
2019-11-19 22:19:03 +01:00
2020-11-08 21:08:19 +01:00
2020-11-08 21:08:19 +01:00
2020-11-15 18:03:56 +01:00

Aedis

Aedis is a redis client designed for

  • Seamless integration with async code
  • Easy and intuitive usage

To use this library include aedis.hpp in your project. Current dendencies are Boost.Asio and libfmt. As of C++23 this library will have no external dependencies.

Example

The examples below will use coroutines, callbacks and futures are supported as well.

awaitable<void> example1(tcp::resolver::results_type const& r)
{
   tcp_socket socket {co_await this_coro::executor};

   co_await async_connect(socket, r);

   auto cmd = ping();
   co_await async_write(socket, buffer(cmd));

   resp::buffer buffer;
   resp::response res;
   co_await resp::async_read(socket, buffer, res);

   resp::print(res.res);
}

Command pipelines can be generated easily

awaitable<void> example2(tcp::resolver::results_type const& r)
{
   tcp_socket socket {co_await this_coro::executor};

   co_await async_connect(socket, r);

   auto cmd = multi()
            + ping()
            + incr("age")
            + exec()
	    + quit()
	    ;

   co_await async_write(socket, buffer(cmd));

   resp::buffer buffer;
   for (;;) {
      resp::response res;
      co_await resp::async_read(socket, buffer, res);
      resp::print(res.res);
   }
}

STL containers are also suported

awaitable<void> example3(tcp::resolver::results_type const& r)
{
   tcp_socket socket {co_await this_coro::executor};

   co_await async_connect(socket, r);

   std::list<std::string> a
   {"one" ,"two", "three"};

   std::set<std::string> b
   {"a" ,"b", "c"};

   std::map<std::string, std::string> c
   { {{"Name"},      {"Marcelo"}} 
   , {{"Education"}, {"Physics"}}
   , {{"Job"},       {"Programmer"}}
   };

   std::map<int, std::string> d
   { {1, {"foo"}} 
   , {2, {"bar"}}
   , {3, {"foobar"}}
   };

   auto cmd = ping()
            + role()
            + flushall()
            + rpush("a", a)
            + lrange("a")
            + del("a")
            + multi()
            + rpush("b", b)
            + lrange("b")
            + del("b")
            + hset("c", c)
            + hincrby("c", "Age", 40)
            + hmget("c", {"Name", "Education", "Job"})
            + hvals("c")
            + hlen("c")
            + hgetall("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")
	    + quit()
	    ;

   co_await async_write(socket, buffer(cmd));

   resp::buffer buffer;
   for (;;) {
      resp::response res;
      co_await resp::async_read(socket, buffer, res);
      resp::print(res.res);
   }
}
Description
Mirrored via gitea-mirror
Readme 6.7 MiB
Languages
C++ 96%
Python 1.4%
CMake 1.2%
Java 0.3%
Rust 0.3%
Other 0.7%