0

I want to insert data to redis in C. I found hiredis library.

I wrote an example:

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

I don't know how to use SADD command. Please, help me.

Termininja
  • 6,620
  • 12
  • 48
  • 49
sam
  • 1,363
  • 1
  • 20
  • 32

1 Answers1

0

The Correct Answer is

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

The key is first I have to use this redisAppendCommand command. the second key is redisAppendCommand command only insert it into buffer after this command I have to use this redisGetReply command to make it permanent.

sam
  • 1,363
  • 1
  • 20
  • 32