xRedis API  1.1
The C++ Client API for Redis server
demo.cpp

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"
// AP Hash Function
unsigned int APHash(const char *str) {
unsigned int hash = 0;
int i;
for (i=0; *str; i++) {
if ((i& 1) == 0) {
hash ^= ((hash << 7) ^ (*str++) ^ (hash >> 3));
} else {
hash ^= (~((hash << 11) ^ (*str++) ^ (hash >> 5)));
}
}
return (hash& 0x7FFFFFFF);
}
#define CACHE_TYPE_1 1
#define CACHE_TYPE_2 2
RedisNode RedisList1[1]=
{
{0,"127.0.0.1", 7000, "", 8, 5}
};
int main(int argc, char **argv) {
xRedisClient xRedis;
xRedis.Init();
xRedis.ConnectRedisCache(RedisList1, 1, CACHE_TYPE_1);
const char *key = "test";
const char *value = "test value";
RedisDBIdx dbi(&xClient);
dbi.CreateDBIndex(key, APHash, CACHE_TYPE_1);
bool bRet = xClient.set(dbi, key, value)
if(bRet){
printf("success \r\n");
} else {
printf("error [%s] \r\n", dbi.GetErrInfo());
}
string strValue;
bRet = xRedis.get(dbi, key, strValue);
if (bRet) {
printf("%s \r\n", strValue.c_str());
} else {
printf("error [%s] \r\n", dbi.GetErrInfo());
}
return 0;
}

Generated on Fri Oct 23 2015 13:13:56 for xRedis API version 1.1.