2016-07-17 6 views
0

Je veux insérer des données à redis en C. J'ai trouvé hiredis bibliothèque.Comment utiliser la commande SADD dans hiredis?

j'ai écrit un exemple:

redisContext *c = redisConnect("127.0.0.1", 6379); 
if (c != NULL && c->err) 
{ 
    printf("Error: %s\n", c->errstr); 
    // handle error 
} else 
{ 
    printf("Connected to Redis\n"); 
} 

redisReply *reply; 
reply = (redisReply *)redisCommand(c, "AUTH 123456"); 


if(reply->type==5) 
{ 
    reply = (redisReply *)redisCommand(c,"SET %d %d",32,111); 
    freeReplyObject(reply); 

    reply = (redisReply *)redisCommand(c,"GET %d",32); 
    printf("%s\n",reply->str); 

    int ii = redisAppendCommand(c,"SADD %d %d",32,33);// MY PROBLEM IS HERE 
    printf("-------SADD---------------- %d\n",ii); 

Je ne sais pas comment utiliser la commande SADD. Aidez-moi, s'il vous plaît.

Répondre

0

La bonne réponse est

redisReply *rreply; 
char buffer[4096]; 
sprintf(buffer,"%u,%u,%u,%u,%s,%u,%d", 1,2,3,4,"HI",5,6); 
redisAppendCommand(c,"SADD %s %s","slog1",buffer); 
redisGetReply(c,(void**)rreply); 

La clé est d'abord je dois utiliser cette commande redisAppendCommand. la deuxième clé est la commande redisAppendCommand seulement l'insérer dans le tampon après cette commande je dois utiliser cette commande redisGetReply pour le rendre permanent.