c++ - 如何在 hiredis 中使用 SADD 命令?

标签 c++ c database redis hiredis

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

最佳答案

正确答案是

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 命令使其永久化。

关于c++ - 如何在 hiredis 中使用 SADD 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38421453/

相关文章:

c++ - 将整数转换为字节数组时获取奇数字符

c++ - 从函数内部的对象 vector 中释放内存

c - 来自 Linux 内核模块的暂停指令不起作用

php - 函数 : Database connection in function or pass it as argument? 的最佳情况是什么

php MySQL - 帐户登录错误

c++ - 同时访问列表中的元素及其后继元素

c++ - 避免使用虚方法构造具有空基类的构造函数

c - 这个函数可以在c中将二进制转换为整数吗

c - 在为所有枚举值定义大小写后,编译器仍然说 : "control reaches end of non-void function"

sql - 加入查询不等于