hiredis redisCommand为Raspberry Pi 4上的所有内容返回null

我有Raspberry pi 4B,带有最新的raspbian和更新的软件。我使用它们的安装说明从github源安装了hiredis库。当我尝试在普通计算机上运行以下代码时,一切正常,但在Raspberry Pi 4B redisCommand上始终返回null。当我使用SET命令时,数据库已更新。

代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hiredis/hiredis.h>


int main (int argc,char **argv) {
    redisReply *reply;
    redisContext *c;

    c = redisConnect("127.0.0.1",6379);
    if (c->err) {
        printf("error: %s\n",c->errstr);
        return 1;
    }


    /* Set a key */
    reply = redisCommand(c,"SET %s %s","test","Hello World");
    printf("SET: %s\n",reply->str);
    printf("error: %s\n",c->errstr);
    freeReplyObject(reply);

    redisFree(c);
    return 0;
}

编译:{{1​​}}

运行:

gcc redis-test-rw.c -o redis-test-rw -g -lhiredis

此呼叫后的Redis:

pi@rpi:~ $ ./redis-test-rw 
SET: (null)
error: 
pi@rpi:~ $

Redis pi@rpi:~ $ redis-cli 127.0.0.1:6379> GET test "Hello World" 127.0.0.1:6379> pi@rpi:~ $ 命令:

MONITOR

我对此感到非常困惑,因为在以前的Raspberry pi 3B上,hireddis没有问题,在计算机上也没问题。

感谢前进!

编辑: Valgrind报告:

127.0.0.1:6379> MONITOR
OK
1577573389.883836 [0 127.0.0.1:47228] "SET" "test" "Hello World"
Advanture 回答:hiredis redisCommand为Raspberry Pi 4上的所有内容返回null

编译此示例代码并验证结果:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hiredis/hiredis.h>

int main (int argc,char **argv) {
    redisReply *reply;
    redisContext *c;

    c = redisConnect("127.0.0.1",6379);
    if (c->err) {
        printf("error: %s\n",c->errstr);
        return 1;
    }

    /* PINGs */
    reply = redisCommand(c,"PING %s","Hello World");
    printf("RESPONSE: %s\n",reply->str);
    printf("error: %s\n",c->errstr);
    freeReplyObject(reply);

    redisFree(c);
    return 0;
}

应打印:

RESPONSE: Hello World
error:
本文链接:https://www.f2er.com/2846808.html

大家都在问