hanzmyco / redis_client

a redis client supports cluster

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Description

  • Only two files included. One hpp file and one cpp file.
  • Depend on hiredis.
  • Support both single node mode and cluster mode.
  • Support pipeline.
  • Use connection pool.
  • Thread safe.
  • Reconnect automatically.
  • Do not support windows yet. Find a read-write lock to replace the 'pthread_rwlock_t' if you want to use this on windows:)
  • (Thanks for the Brian's help.)

TODO

  • Optimize the reconnect function.
  • Support pub/sub and transaction.
  • Support scan in an unsafe way.

License

This program was written by Shawn XU and is released under the BSD license.

Usage

#include "RedisClient.hpp"

int main()
{
    CRedisClient redisCli;
    if (!redisCli.Initialize("127.0.0.1", 6379, 2, 10))
    {
        std::cout << "connect to redis failed" << std::endl;
        return -1;
    }

    std::string strKey = "key_1";
    std::string strVal;
    if (redisCli.Get(strKey, &strVal) == RC_SUCCESS)
    {
        std::cout << "key_1 has value " << strVal << std::endl;
        return 0;
    }
    else
    {
        std::cout << "request failed" << std::endl;
        return -1;
    }
}

You can view the test file if you want to know more using details about this client.

About

a redis client supports cluster


Languages

Language:C++ 84.0%Language:C 14.5%Language:Makefile 1.5%