This is an example of how to use the xRedis.
This demo connect to single redis server with connection pool
More details about this example.
#include "xRedisClient.h"
#include <cstdio>
#include <unistd.h>
using namespace xrc;
enum {
CACHE_TYPE_1,
CACHE_TYPE_MAX,
};
{ .
dbindex = 0, .host =
"127.0.0.1", .port = 6379, .passwd =
"", .poolsize = 4, .timeout = 5, .role = MASTER }
};
void log_demo(int level, const char* line)
{
printf("xRedis %u %s", level, line);
}
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
xRedis.
Init(CACHE_TYPE_MAX);
xRedis.
ConnectRedisCache(RedisList1,
sizeof(RedisList1) /
sizeof(
RedisNode),
1, CACHE_TYPE_1);
const char* key = "test";
const char* value = "test value";
index.Create(key);
bool bRet = xRedis.
set(index, key, value);
if (bRet) {
printf("success \r\n");
} else {
printf("error %s \r\n", index.GetErrInfo());
}
std::string strValue;
bRet = xRedis.
get(index, key, strValue);
if (bRet) {
printf("%s \r\n", strValue.c_str());
} else {
printf("error %s ", index.GetErrInfo());
}
while (true)
{
usleep(1000*1000*6);
}
return 0;
}