Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

redis-plus-plus

> 数据库
Open source

Redis client written in C++

2.0K stars0 likes2 views
WebsiteGitHub

About

Redis client written in C++

redis-plus-plus

中文交流群

  • Overview
    • Features
  • Installation
    • Install hiredis
    • Install redis-plus-plus
    • Run Tests (Optional)
    • Use redis-plus-plus In Your Project
    • Install using Conan
  • Getting Started
  • API Reference
    • Connection
    • Send Command to Redis Server
    • Exception
    • Generic Command Interface
    • Publish/Subscribe
    • Pipeline
    • Transaction
    • Redis Cluster
    • Redis Sentinel
    • Redis Stream
    • Redis Modules
    • Async Interface
    • Coroutine Interface
  • Redis Patterns
    • Redlock
  • Breaking Changes
  • Author

Overview

This is a C++ client library for Redis. It's based on hiredis, and is compatible with C++11 and later versions. Besides Redis, it also works with other key-value stores supporting RESP (REdis Serialization Protocol), e.g. Valkey, DragonflyDB, KeyDB.

NOTE: I'm not a native speaker. So if the documentation is unclear, please feel free to open an issue or pull request. I'll response ASAP.

Features

  • Most commands for Redis.
  • Connection pool.
  • Redis scripting.
  • Thread safe unless otherwise stated.
  • Redis publish/subscribe.
  • Redis pipeline.
  • Redis transaction.
  • Redis Cluster.
  • Redis Sentinel.
  • STL-like interfaces.
  • Generic command interface.
  • Redis Stream.
  • Redlock.
  • Redis ACL.
  • TLS/SSL support.
  • Sync and Async interface.
  • Coroutine support.

Installation

Install hiredis

Since redis-plus-plus is based on hiredis, you should install hiredis first. The minimum version requirement for hiredis is v0.12.1. However, the latest stable release of hiredis is always recommended.

NOTE: You must ensure that there's only 1 version of hiredis installed. Otherwise, you might get some weird problems. Check the following issues for example: issue 135, issue 140 and issue 158.

Normally, you can install hiredis with a C++ package manager, and that's the easiest way to do it, e.g. sudo apt-get install libhiredis-dev. However, if you want to install the latest code of hiredis, or a specified version (e.g. async support needs hiredis v1.0.0 or later), you can install it from source.

Note again: DO NOT INSTALL MULTIPLE VERSIONS OF HIREDIS.

bash
git clone https://github.com/redis/hiredis.git

cd hiredis

make

sudo make install

By default, hiredis is installed at /usr/local. If you want to install hiredis at non-default location, use the following commands to specify the installation path.

bash
make PREFIX=/non/default/path

make PREFIX=/non/default/path install

Install redis-plus-plus

redis-plus-plus is built with CMAKE.

bash
git clone https://github.com/sewenew/redis-plus-plus.git

cd redis-plus-plus

mkdir build

cd build

cmake ..

make

sudo make install

cd ..

If hiredis is installed at non-default location, you should use CMAKE_PREFIX_PATH to specify the installation path of hiredis. By default, redis-plus-plus is installed at /usr/local. However, you can use CMAKE_INSTALL_PREFIX to install redis-plus-plus at non-default location.

bash
cmake -DCMAKE_PREFIX_PATH=/path/to/hiredis -DCMAKE_INSTALL_PREFIX=/path/to/install/redis-plus-plus ..

Since version 1.3.0, by default, redis-plus-plus is built with the -std=c++17 standard. So that we can use the std::string_view and std::optional features. However, it can also be built with the -std=c++11 or -std=c++14 standard, and in that case, we have our own simple implementation of std::string_view and std::optional. In order to explicitly specify c++ standard, you can use the following cmake flag: -DREDIS_PLUS_PLUS_CXX_STANDARD=11.

bash
cmake -DCMAKE_PREFIX_PATH=/path/to/hiredis -DCMAKE_INSTALL_PREFIX=/path/to/install/redis-plus-plus -DREDIS_PLUS_PLUS_CXX_STANDARD=11 ..

NOTE: You should build redis-plus-plus and your application with the same standard, e.g. if you build redis-plus-plus with C++17 standard, you MUST also build your application code with C++17 standard.

When compiling redis-plus-plus, it also compiles a test program, which might take a while. However, you can disable building test with the following cmake option: -DREDIS_PLUS_PLUS_BUILD_TEST=OFF.

bash
cmake -DCMAKE_PREFIX_PATH=/path/to/hiredis -DCMAKE_INSTALL_PREFIX=/path/to/install/redis-plus-plus -DREDIS_PLUS_PLUS_BUILD_TEST=OFF ..

By default, redis-plus-plus builds both a static library and a shared library. If you only want to build one of them, you can disable the other with -DREDIS_PLUS_PLUS_BUILD_STATIC=OFF or -DREDIS_PLUS_PLUS_BUILD_SHARED=OFF.

redis-plus-plus builds static library with -fPIC option, i.e. Position Independent Code, by default. However, you can disable it with -DREDIS_PLUS_PLUS_BUILD_STATIC_WITH_PIC=OFF.

FetchContent

You can also use cmake's FetchContent feature to install redis-plus-plus. Check this for an example.

Windows Support

Now hiredis has Windows support, and since Visual Studio 2017, Visual Studio has built-in support for CMake. So redis-plus-plus also supports Windows platform now. It has been fully tested with Visual Studio 2017 and later on Win 10. I'm not familiar with Visual Studio environment, and the following doc might not be accurate. If you're familiar with the Windows platform, feel free to update this doc on how to install redis-plus-plus on Windows.

CMake Support On Visual Studio

The following are some links on how to build CMake project with Visual Studio 2017 or later. If you're not familiar with it, you'd better read these instructions first:

  • CMake support in Visual Studio
  • CMake projects in Visual Studio
  • CMakeSettings.json schema reference
  • Open a project from a GitHub repo

NOTE: IMHO, Visual Studio 2017's support for CMake project is not very mature, and I recommend you to build hiredis and *redis-plus-plus with Visual Studio 2019.

Build hiredis

First of all, you need to get the latest code of hiredis on master branch. Older version might not support Windows platform. hiredis' CMakeLists.txt uses add_compile_definitions method, which is only supported by cmake 3.12 or later. However, Visual Studio 2017's cmake version is older than that. So if you're using Visual Studio 2017, you need to comment the following line in the CMakeLists.txt file:

cmake
#IF(WIN32)
#    ADD_COMPILE_DEFINITIONS(_CRT_SECURE_NO_WARNINGS WIN32_LEAN_AND_MEAN)
#ENDIF()

You can use the Open Folder feature to open hiredis project, and build it with the instructions (links) mentioned above.

Build redis-plus-plus

Since redis-plus-plus depends on hiredis, we need to specify the installation paths of hiredis before building it. You can use the Open Folder feature to open redis-plus-plus project. You need to edit the CMakeSetting.json file (automatically generated by Visual Studio) to set HIREDIS_HEADER, HIREDIS_LIB and TEST_HIREDIS_LIB variables to specify the installation path of hiredis headers, installation path of hiredis dynamic library and installation path of hiredis static library. The following is an example of CMakeSetting.json file:

…

Then you can build it with the instructions (links) mentioned above.

NOTE:

  • Since 1.3.0, redis-plus-plus is built with C++17 by default, and you should also set your application code to be built with C++17. If you still want to build the redis-plus-plus with C++11, you can set the REDIS_PLUS_PLUS_CXX_STANDARD cmake option to 11.
  • TLS/SSL support has not been tested on Windows yet.
Build with Visual Studio

If you want to build the project with Visual Studio and have questions about it, please follow the steps below. The following is tested on Visual Studio 2022 Community.

powershell
# download two projects into this folder
mkdir redis++

cd redis++
# make sure you create a hiredis first to work as a library
mkdir hiredis-lib
cd hiredis-lib
mkdir lib

git clone https://github.com/redis/hiredis.git
cd hiredis

So far it should be fine with each step. Then open CMakeLists.txt file. Modify the following line and comment it out

txt
...
# SET(CMAKE_DEBUG_POSTFIX d)
...

Then go back to hiredis project folder

powershell
mkdir build
cd build
# convert project into visual studio 2022, if necessary choose you version e.g 19 2019 etc.
cmake -G "Visual Studio 17 2022" ..
./hiredis.sln

Set hiredis as Startup Project then click Build Solution in Debug Mode

After successfull build, copy all the files under Debug into hiredis-lib/lib folder

Here the work for hiredis should be finished.

Then go back to redis++ folder. Open Terminal here

powershell
git clone https://github.com/sewenew/redis-plus-plus.git
cd redis-plus-plus
mkdir build
cd build

Now you should always have openssl on your PC, otherwise can use chocolatey to install it. For Visual Studio 2022 please install pthread separately using vpckg, following this link

After all preparation. If you want to convert all projects then

powershell
cmake -DCMAKE_PREFIX_PATH="$(ABSOLUTE_PATH)\hiredis-lib" -G "Visual Studio 17 2022" ..
cd build
./redis++.sln

set redis++_static as Startup Project then click Build Solution

So far build has been successfully finished!

The Order of Header Files

On Windows platform, if your application code also needs to include windows.h. You must ensure that sw/redis++/redis++.h is included before windows.h. Check this issue for detail.

Building a redis-plus-plus Debian Package (Optional)

Basic support for building a GNU/Debian package is supplied with the use of cmake. The following example shows how to build the Debian package:

bash
mkdir build; cd build
cmake ..
cpack -G DEB

The install prefix may be modified as follows:

bash
mkdir build; cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
cpack -G DEB

Run Tests (Optional)

redis-plus-plus has been fully tested with the following compilers:

…

If you build redis-plus-plus with -DREDIS_PLUS_PLUS_BUILD_TEST=ON (the default behavior, and you can disable building test with -DREDIS_PLUS_PLUS_BUILD_TEST=OFF), you'll get a test program in build/test directory: build/test/test_redis++.

In order to run the tests, you need to set up a Redis instance, and a Redis Cluster. Since the test program will send most of Redis commands to the server and cluster, you need to set up Redis of the latest version. Otherwise, the tests m

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++c-plus-plusconnection-poolcppcpp11

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库