Skip to content
deep edited this page May 23, 2017 · 2 revisions
#include<stdio.h>
#include<hircluster.h>
int main()
{
	redisClusterContext *cc;
	redisReply *reply;

        cc = redisClusterContextInit();
        redisClusterSetOptionAddNodes(cc, "127.0.0.1:34501,127.0.0.1:34502,127.0.0.1:34503");
        redisClusterConnect2(cc);
	if(cc == NULL || cc->err)
	{
		printf("connect error : %s\n", cc == NULL ? "NULL" : cc->errstr);
		return -1;
	}
 
	redisClusterAppendCommand(cc, "set key1 value1");
	redisClusterAppendCommand(cc, "get key1");
	redisClusterAppendCommand(cc, "mset key2 value2 key3 value3");
	redisClusterAppendCommand(cc, "mget key2 key3");
	
	redisClusterGetReply(cc, &reply);  //for "set key1 value1"
	freeReplyObject(reply);
	redisClusterGetReply(cc, &reply);  //for "get key1"
	freeReplyObject(reply);
	redisClusterGetReply(cc, &reply);  //for "mset key2 value2 key3 value3"
	freeReplyObject(reply);
	redisClusterGetReply(cc, &reply);  //for "mget key2 key3"
	freeReplyObject(reply);
	
	redisCLusterReset(cc);
		
	...
	...
	
	redisClusterFree(cc);
	return 0;
}
Clone this wiki locally