drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.62k stars 1.12k forks source link

在drogon/nosql/RedisResult.h中似乎有拼写错误 #1415

Open silentmissile opened 2 years ago

silentmissile commented 2 years ago

在drogon/nosql/RedisResult.h中,可以看到

enum class RedisResultType
{
    kInteger = 0,
    kString,
    kArray,
    kStatus,
    kNil,  //  从语义上看似乎应该用kNull
    kError
};

另外同一份文件中有

    /**
     * @brief return true if the result object is nil.
     *
     * @return true
     * @return false
     */
    bool isNil() const noexcept;

    /**
     * @brief Check if the result object is not nil.
     *
     * @return true
     * @return false
     */
    explicit operator bool() const
    {
        return !isNil();
    }

这里用的是kNilisNil

但是在中文文档 https://github.com/drogonframework/drogon-docs/blob/master/CHN-17-Redis.md 里面写的是:

redisClient->execCommandAsync(
    [](const drogon::nosql::RedisResult &r) {
        if (r.type() == RedisResultType::kNull)  // 这里是kNull
            LOG_INFO << "Cannot find variable associated with the key 'name'";
        else
            LOG_INFO << "Name is " << r.asString();
    },
    [](const std::exception &err) {
        LOG_ERROR << "something failed!!! " << err.what();
    },
    "get name");

在英文版文档 https://github.com/drogonframework/drogon-docs/blob/master/ENG-17-Redis.md 里面却是

redisClient->execCommandAsync(
    [](const drogon::nosql::RedisResult &r) {
        if (r.type() == RedisResultType::kNil) // 这里是kNil
            LOG_INFO << "Cannot find variable associated with the key 'name'";
        else
            LOG_INFO << "Name is " << r.asString();
    },
    [](const std::exception &err) {
        LOG_ERROR << "something failed!!! " << err.what();
    },
    "get name");

在RedisResult.cc中,有两段代码,用的是kNilisNil

RedisResultType RedisResult::type() const noexcept
{
    switch (result_->type)
    {
        case REDIS_REPLY_STRING:
            return RedisResultType::kString;
        case REDIS_REPLY_ARRAY:
            return RedisResultType::kArray;
        case REDIS_REPLY_INTEGER:
            return RedisResultType::kInteger;
        case REDIS_REPLY_NIL:
            return RedisResultType::kNil;
        case REDIS_REPLY_STATUS:
            return RedisResultType::kStatus;
        case REDIS_REPLY_ERROR:
        default:
            return RedisResultType::kError;
    }
}
bool RedisResult::isNil() const noexcept
{
    return type() == RedisResultType::kNil;
}

也就是说,只有在中文文档中,才用kNull,其他各个文件用的都是kNilisNil

但是从语义上看,应该是kNullisNull

an-tao commented 2 years ago

nil和null这里是同一个意思,如果非说区别,据说nil一般指空对象,null指空指针,而且redis是使用的nil术语,所以,应该修改中文文档,谢谢你的反馈~ @silentmissile