HiRedis:no auth Authentication required错误

使用hiredis连接redis_server时出现 no auth Authentication required错误

这说明你设置了redis_server密码,文件在/etc/redis/redis.conf里面找到requirepass字段
#使用hiredis
void RedisTools::init()
{
    struct timeval timeout = { 1, 500000 };
    m_redis = redisConnectWithTimeout(ip.c_str(), port, timeout);//建立连接
    if (m_redis->err)
    {
        LOG(INFO) << "connect redis error" << m_redis->errstr;
        return;
    }
    redisReply *reply;
    reply = (redisReply *)redisCommand(m_redis, "AUTH %s", "123456");//认证密码
    if (reply->type == REDIS_REPLY_ERROR)
    {
        LOG(ERROR) << "auth error";
    }
    else
    {
        LOG(INFO) << "auth success";
    }
    freeReplyObject(reply);
}
暂无评论
发表新评论