增加redis不可达的错误处理。

This commit is contained in:
zhengchao
2018-05-23 22:38:27 +08:00
parent 1cef03375a
commit 3e07461a20
3 changed files with 23 additions and 9 deletions

View File

@@ -46,9 +46,9 @@ static redisContext * connect_redis(const char*redis_ip, int redis_port, int red
redisContext * ctx;
ctx=redisConnectWithTimeout(redis_ip, redis_port,connect_timeout);
if(ctx==NULL)
if(ctx==NULL||ctx->err)
{
printf("Unable to connect %s:%d db%d\n",redis_ip,redis_port,redis_db);
printf("Unable to connect %s:%d db%d : %s\n",redis_ip,redis_port,redis_db, ctx==NULL?"Unknown":ctx->errstr);
return NULL;
}
reply=_wrap_redisCommand(ctx, "select %d",redis_db);