悟了个空 2019-05-13 19:29 采纳率: 0%
浏览 275

C/C++ 调用libhiredisAPI接口报错, 怎么解决?

这是集群中的一个节点, 连接之后直接调用发送命令, 然后就报错
MOVED 12539 192.168.6.251:19002

char *hostname = "192.168.6.251";
int port = 19003;

struct timeval timeout = { 1, 500000 }; // 1.5 seconds
//c = redisConnect(hostname, port);
redisContext *con = redisConnectWithTimeout(hostname, port, timeout);
if (con == NULL || con->err) {
    if (con) {
        printf("Connection error: %s\n", con->errstr);
        redisFree(con);
    } else {
        printf("Connection error: can't allocate redis context\n");
    }
    return -1;
}
redisReply *reply = (redisReply *)redisCommand(con,"set key hello");
printf("Set return: %s\n", reply->str);
freeReplyObject(reply);
freeRedis(con);
  • 写回答

1条回答 默认 最新

  • summer_linked 2019-05-24 16:25
    关注

    判断下结果包含 MOVED就重连,再次执行。
    if (reply->type == REDIS_REPLY_ERROR &&
    (!strncmp(reply->str,"MOVED",5) || !strcmp(reply->str,"ASK")))
    {
    }

    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程