gpt4 book ai didi

c++ - 'CREATE' 附近偏移量 8 处的 RedisGraph 语法错误

转载 作者:行者123 更新时间:2023-11-30 04:41:20 24 4
gpt4 key购买 nike

我在我的 C++ 代码中使用 hiredis 库来执行 RedisGraph 命令。当我尝试在 C++ 代码中执行“创建”命令时,它会抛出错误,但是当我在命令行中执行完全相同的命令时,它工作正常。这是怎么回事?也许我做错了什么? Redis 服务器版本是 4.0.9,这是我在 C++ 中的代码:

#include <iostream>
#include <cstdint>
#include <cstring>
#include <hiredis.h>
using namespace std;
int main(int argc, char** argv) {
unsigned int j, isunix = 0;
redisContext *c;
redisReply *reply;
const char *hostname = (argc > 1) ? argv[1] : "127.0.0.1";
int port = (argc > 2) ? atoi(argv[2]) : 6379;
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
if (isunix) {
c = redisConnectUnixWithTimeout(hostname, timeout);
} else {
c = redisConnectWithTimeout(hostname, port, timeout);
}
if (c == NULL || c->err) {
if (c) {
printf("Connection error: %s\n", c->errstr);
redisFree(c);
} else {
printf("Connection error: can't allocate redis context\n");
}
}
const char * destPtr = "GRAPH.QUERY Project \"CREATE (:User {userId:9})\"";
std::cout<<destPtr<<std::endl;
reply = (redisReply *)redisCommand(c,destPtr);
//
printf(reply->str);
freeReplyObject(reply);
return 0;
}

它抛出这个错误:

Syntax error at offset 8 near 'CREATE'

最佳答案

没试过,但值得一试:

reply = (redisReply *)redisCommand(c, "GRAPH.QUERY key:%s %s", "Project", "CREATE (:User {userId:9})");

https://github.com/redis/hiredis#sending-commands

关于c++ - 'CREATE' 附近偏移量 8 处的 RedisGraph 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59142219/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com