百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

redox

> 编程语言
开源

面向现代、异步且极其快速的 C++11 客户端,用于 Redis

386 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

面向现代、异步且极其快速的 C++11 客户端,用于 Redis

redox

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:

  • Expressive asynchronous and synchronous API, templated by return value
  • Callbacks can be lambdas, class methods, bind expressions, or any std::function
  • Thread-safe - use one client in multiple threads or multiple clients in one
  • Automatic pipelining, even for synchronous calls from separate threads
  • Low-level access when needed
  • Accessible and robust error handling
  • Configurable logging level and output to any ostream
  • Full support for binary data (keys and values)
  • Fast - developed for robotics applications
  • 100% clean Valgrind reports

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

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/s
  • speed_test_async_multi over Unix socket: 901,683 commands/s
  • speed_test_async over TCP: 203,285 commands/s
  • speed_test_async over Unix socket: 301,823 commands/s
  • speed_test_sync over TCP: 21,072 commands/s
  • speed_test_sync over Unix socket: 24,911 commands/s

A mid-range laptop gives comparable results. Numbers can be much higher on a high-end machine.

Tutorial

This section introduces the main features of redox. Look in examples/ for more inspiration.

Hello world

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!

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言