2016-07-17 8 views
0

Cで赤字にデータを挿入したいのですが、hiredisというライブラリが見つかりました。hiredisでSADDコマンドを使用するには?

私は例を書いた:

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); 

私はSADDコマンドを使用する方法がわかりません。私を助けてください。

答えて

0

正解は鍵が最初に私は、このredisAppendCommandコマンドを使用する必要がある

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); 

です。 2番目のキーはredisAppendCommandコマンドで、このコマンドの後にバッファに挿入するだけです。このredisGetReplyコマンドを使用して永続化する必要があります。

関連する問題