Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs V0.0.1 Jul 14, 2019
examples [crpc] add sync client Nov 1, 2019
soce-redis V0.0.1 Jul 14, 2019
src [crpc] add sync client Nov 1, 2019
CMakeLists.txt V0.0.1 Jul 14, 2019


soce-redis is a C++ client, which can be used to access the sever with the same interface, no matter what mode(single, sentinel, cluster) the server use. It also support pipeline and async. 中文版点这里


A SoceRedis instance must be initialized with the configuration which is a string.

  • single mode

  • sentinel mode

  • cluster mode

The password should be set to "none" if it is not necessary. timeout is optional, it is used for read/write/connect.

string conf = "none@";
SoceRedis clt;

SoceRedis API

soce-redis support single command and pipeline。And you can access the result by iterator. There are only a few interfaces, it's easy to use.

  • int init(const std::string& conf)
    @see initialization.

  • int exec(Fmt fmt)
    Execute single command.

  • void clear()
    Clear the cached command for pipeline.

  • int append(Fmt fmt)
    Add pipeline command.

  • int pipeline()
    Execute pipeline commands.

  • iterator begin()
    Return the beginning iterator of the result.

  • iterator end()
    Return the ending iterator of the result.


iterator is used to access the result. It point to a SoceRedisReply instance. You can used the interface of SoceRedisReply to access the result.

  • int get_type(SoceRedisType& type)
  • int get_type(SoceRedisType& type)
  • int get_str(std::string& val)
  • int get_array_size(int& size)
  • int get_array_begin(SoceRedisIterator& iter)
  • int get_array_end(SoceRedisIterator& iter)
  • int get_int(int& val)
  • int get_status(std::string& val)
  • int get_error(std::string& val)

helper macros

The type of parameter used by exec() is "Fmt" which is defined as below:

using Fmt = std::function<void(Param&)>;
int exec(Fmt fmt);

Macro soce_redis_docmd and soce_redis_append are supplied to simplify the usage of SoceRedis.

sample : single command

soce_redis_docmd(clt, "set" << "a" << "b");
string val;
clt.begin()->get_status(val); // get the result

sample : pipeline command

soce_redis_append(clt, "set" << "a" << "b");
soce_redis_append(clt, "get" << "a");
for (auto& result : clt){
    // handle the results


It's easy to implement async-access by coroutine.
@see soce-redis/sample/sample-async

More samples

@see soce-redis/sample。

You can’t perform that action at this time.