Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redisReply is null #116

Open
narayanashanubhog opened this issue Jul 4, 2019 · 4 comments
Open

redisReply is null #116

narayanashanubhog opened this issue Jul 4, 2019 · 4 comments

Comments

@narayanashanubhog
Copy link

narayanashanubhog commented Jul 4, 2019

If i use the below code, i'm getting redisReply is null

struct timeval timeout = { 1, 500000 }; // 1.5 seconds
redisClusterContext redis = redisClusterContextInit();
redisClusterSetOptionAddNodes(redis, "127.0.0.1:7000");
redisClusterSetOptionConnectTimeout(redis, timeout);
redisClusterConnect2(redis);
if (redis != NULL && redis->err) {
printf("Error: %s\n",redis->errstr);
// handle error
exit(-1);
}
reply = (redisReply
) redisClusterCommand(redis, "INFO");
if (reply == NULL){
error(0, "REDIS: INFO reply null to get version failed!");
}

When i add redisClusterSetOptionRouteUseSlots(redis); //The function that has to be called.
Its throwing below exception
Error: Command(cluster slots) reply error: node ip is not string.

Im using the redis version 5. Thanks in advance.

@raghuiisc
Copy link

As pointed in #33 .. INFO is command for cluster node. For this to execute we need to execute rediscommand on node.

I tried the code locally by adding "redisClusterSetOptionRouteUseSlots(redis)" i do not see any issue. For exact error please print "redis->errstr".

If u do not want to use "redisClusterSetOptionRouteUseSlots(redis)", there is a bug in parsing the output of cluster nodes which is causing the issue. To fix, please apply the below patch.

diff --git a/hircluster.c b/hircluster.c
index b051936..7538abb 100644
--- a/hircluster.c
+++ b/hircluster.c
@@ -23,6 +23,8 @@

#define IP_PORT_SEPARATOR ":"

+#define PORT_SEPARATOR "@"
+
#define CLUSTER_ADDRESS_SEPARATOR ","

#define CLUSTER_DEFAULT_MAX_REDIRECT_COUNT 5
@@ -534,7 +536,9 @@ static cluster_node *node_get_with_nodes(
sds *node_infos, int info_count, uint8_t role)
{
sds *ip_port = NULL;

  • sds *port = NULL;
    int count_ip_port = 0;

  • int count_port = 0;
    cluster_node *node;

    if(info_count < 8)
    @@ -578,9 +582,19 @@ static cluster_node *node_get_with_nodes(
    goto error;
    }
    node->host = ip_port[0];

  • node->port = hi_atoi(ip_port[1], sdslen(ip_port[1]));
  • //node->port = hi_atoi(ip_port[1], sdslen(ip_port[1]));
    node->role = role;

  • port = sdssplitlen(ip_port[1], sdslen(ip_port[1]),

  •          PORT_SEPARATOR, strlen(PORT_SEPARATOR), &count_port);
    
  • if(port == NULL || ((count_port != 1) && (count_port != 2)))

  • {

  •    __redisClusterSetError(cc,REDIS_ERR_OTHER,
    
  •        "split ip port error");
    
  •    goto error;
    
  • }

  • node->port = hi_atoi(port[0], sdslen(port[0]));

  • sdsfreesplitres(port, count_port);
    sdsfree(ip_port[1]);
    free(ip_port);

@@ -595,6 +609,11 @@ error:
sdsfreesplitres(ip_port, count_ip_port);
}

  • if(port != NULL)
  • {
  •    sdsfreesplitres(port, count_port);
    
  • }
  • if(node != NULL)
    {
    hi_free(node);

@narayana-plivo
Copy link

@raghuiisc :The same above code works in redis version 4.0. But latest version of redis > 5. For any redisClusterCommand, it will give redis reply null

@raghuiisc
Copy link

redis reply is NULL, but can you please print "redis->errstr" and exact code u are executing. I tried locally and it was working fine.

@narayana-plivo
Copy link

there is no issue in connecting redis cluster.
if (redis != NULL && redis->err) {
printf("Error: %s\n",redis->errstr);
// handle error
exit(-1);
}

Only redisClusterCommand is returning Null always for any command you execute like hmset,hmget etc etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants