bool LuaTable::get()

in common/luatable.cpp [28:76]


bool LuaTable::get(const vector<string> &luaKeys, vector<FieldValueTuple> &values)
{
    if (m_lua.empty() || luaKeys.empty())
    {
        values.clear();
        return false;
    }

    // Assembly redis command args into a string vector
    vector<string> args;
    args.emplace_back("EVALSHA");
    args.emplace_back(loadRedisScript(m_db.get(), m_lua));
    args.emplace_back(to_string(luaKeys.size()));
    for (const auto& k: luaKeys)
    {
        args.emplace_back(k);
    }

    // ARGV[1..4]: counter db, gearbox counter db, table name, separator
    args.emplace_back(to_string(COUNTERS_DB));
    args.emplace_back(to_string(GB_COUNTERS_DB));
    args.emplace_back(getTableName());
    args.emplace_back(getTableNameSeparator());
    args.emplace_back("HGETALL");  // ARGV[5] get all fields
    for (const auto& v: m_luaArgv) // ARGV[6...] extra user-defined
    {
        args.emplace_back(v);
    }

    // Invoke redis command
    RedisCommand command;
    command.format(args);
    RedisReply r(m_db.get(), command, REDIS_REPLY_ARRAY);
    redisReply *reply = r.getContext();

    if (!reply->elements)
        return false;

    if (reply->elements & 1)
        throw system_error(make_error_code(errc::address_not_available),
                           "Unable to connect netlink socket");

    values.clear();
    for (unsigned int i = 0; i < reply->elements; i += 2)
    {
        values.emplace_back(reply->element[i]->str, reply->element[i + 1]->str);
    }
    return true;
}