Modern, asynchronous, and wicked fast C++11 client for Redis
Modern, asynchronous, and wicked fast C++11 client for Redis
Modern, asynchronous, and wicked fast C++11 client for Redis [] (https://travis-ci.org/hmartiro/redox)
Redox is a C++ interface to the Redis key-value store that makes it easy to write applications that are both elegant and high-performance. Communication should be a means to an end, not something we spend a lot of time worrying about. Redox takes care of the details so you can move on to the interesting part of your project.
Features:
Redox is built on top of hiredis and libev. It uses only the asynchronous API of hiredis, even for synchronous commands. There is no dependency on Boost or any other libraries.
Benchmarks are given by averaging the results of ten trials of the speed tests
in examples/ on an AWS t2.medium instance running Ubuntu 14.04 (64-bit) and a
local Redis server.
speed_test_async_multi over TCP: 879,589 commands/sspeed_test_async_multi over Unix socket: 901,683 commands/sspeed_test_async over TCP: 203,285 commands/sspeed_test_async over Unix socket: 301,823 commands/sspeed_test_sync over TCP: 21,072 commands/sspeed_test_sync over Unix socket: 24,911 commands/sA mid-range laptop gives comparable results. Numbers can be much higher on a high-end machine.
This section introduces the main features of redox. Look in examples/ for more inspiration.
Here is the simplest possible redox program:
…c++ Redox rdx;
// Block until connected, localhost by default if(!rdx.connect()) return 1;
auto got_reply = [](Command& c) { if(!c.ok()) return; cout ({"GET", "hello"}, got_reply);
// Do useful work this_thread::sleep_for(chrono::milliseconds(10));
rdx.disconnect(); // Block until disconnected
The `.command()` method returns immediately, so this program doesn't wait for a reply
from the server - it just pauses for ten milliseconds and then shuts down. If we want to
shut down after we get all replies, we could do something like this:
```c++
Redox rdx;
if(!rdx.connect()) return 1;
int total = 10; // Number of commands to run
atomic_int count(0); // Number of replies expected
auto got_reply = [&](Command& c) {
count++;
if(c.ok()) cout ({"GET", "hello"}, got_reply);
// Do useful work
rdx.wait(); // Block until shut down complete
…
c++
Command& c = rdx.commandSync({"GET", "hello"});
if(c.ok()) cout & cmd = rdx.commandLoop({"GET", "hello"}, [](Command& c) {
if(c.ok()) cout ({"GET", "hello"}, [](Command& c) {
if(c.ok()) cout ` containing `GET` and `foo`
as entries. `rdx.vecToStr({"GET", "foo"})` will return the string `GET foo`.
#### No-Wait Mode
Redox provides a no-wait mode, which tells the event loop not to sleep
in between processing events. It means that the event thread will run
at 100% CPU, but it can greatly improve performance when critical. It is
disabled by default and can be enabled with `rdx.noWait(true);`.
## Reply types
These the available template parameters in redox and the Redis
[return types](http://redis.io/topics/protocol) they can hold.
If a given command returns an incompatible type you will get
a `WRONG_TYPE` or `NIL_REPLY` status.
* ``: All reply types, returns the hiredis struct directly
* ``: Simple Strings, Bulk Strings
* ``: Simple Strings, Bulk Strings
* ``: Integers
* ``: Integers (careful about overflow, `long long int` recommended)
* ``: Null Bulk Strings, any other receiving a nil reply will get a NIL_REPLY status
* `>`: Arrays of Simple Strings or Bulk Strings (in received order)
* `>`: Arrays of Simple Strings or Bulk Strings (in sorted order)
* `>`: Arrays of Simple Strings or Bulk Strings (in no order)
## Installation
Instructions provided are for Ubuntu, but all components are platform-independent.
#### Build from source
Get the build environment and dependencies:
sudo apt-get install git cmake build-essential
sudo apt-get install libhiredis-dev libev-dev
Build the library:
mkdir build && cd build
cmake ..
make
Install into system directories (optional):
sudo make install
#### Build examples and test suite
Enable examples using ccmake or the following:
cmake -Dexamples=ON ..
make examples
To run the test suite, first make sure you have
[gtest](https://code.google.com/p/googletest/) set up,
then:
cmake -Dtests=ON ..
make test_redox
./test_redox
#### Build documentation
Redox documentation is generated using [doxygen](http://doxygen.org).
cd docs
doxygen
The documentation can then be viewed in a browser at `docs/html/index.html`.
#### Build RPM and DEB packages
Basic support to build RPMs and DEBs is in the build system. To build them, issue
the following commands:
mkdir release && cd release
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
make package
NOTE: To build RPM packages, you will need rpmbuild.
## Contributing
Redox is in its early stages and I am looking for feedback and contributors to make
it easier, faster, and more robust. Open issues on GitHub or message me directly.
Redox is not currently recommended for production use. It has no support yet for sentinels
or clusters. Feel free to provide them!No open issues yet, or sync has not completed.