【问题标题】:How to use SADD command in hiredis?如何在hiredis中使用SADD命令?
【发布时间】:2016-11-20 03:50:18
【问题描述】:

我想在 C 中向 redis 中插入数据。我找到了hiredis 库。

我写了一个例子:

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 命令。请帮帮我。

【问题讨论】:

    标签: c++ c database redis hiredis


    【解决方案1】:

    正确答案是

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

    关键是首先我要使用这个 redisAppendCommand 命令。 第二个键是 redisAppendCommand 命令,仅在此命令之后将其插入缓冲区,我必须使用此 redisGetReply 命令使其永久化。

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-28
      • 1970-01-01
      • 2013-09-26
      相关资源
      最近更新 更多