static inline std::set runRedisScript()

in common/redisapi.h [69:128]


static inline std::set<std::string> runRedisScript(RedisContext &ctx, const std::string& sha,
        const std::vector<std::string>& keys, const std::vector<std::string>& argv)
{
    SWSS_LOG_ENTER();

    std::vector<std::string> args;

    // Prepare EVALSHA command
    // Format is following:
    // EVALSHA <sha> <size of KEYS> <KEYS> <ARGV>
    args.push_back("EVALSHA");
    args.push_back(sha);
    args.push_back(std::to_string(keys.size()));
    args.insert(args.end(), keys.begin(), keys.end());
    args.insert(args.end(), argv.begin(), argv.end());
    args.push_back("''");

    RedisCommand command;
    command.format(args);

    std::set<std::string> ret;
    try
    {
        RedisReply r(&ctx, command);
        auto reply = r.getContext();
        SWSS_LOG_DEBUG("Running lua script %s", sha.c_str());

        if (reply->type == REDIS_REPLY_NIL)
        {
            SWSS_LOG_ERROR("Got EMPTY response type from redis %d", reply->type);
        }
        else if (reply->type == REDIS_REPLY_INTEGER)
        {
            SWSS_LOG_DEBUG("Got INTEGER response type from redis %d", reply->type);
            ret.emplace(std::to_string(reply->integer));
        }
        else if (reply->type != REDIS_REPLY_ARRAY)
        {
            SWSS_LOG_ERROR("Got invalid response type from redis %d", reply->type);
        }
        else
        {
            for (size_t i = 0; i < reply->elements; i++)
            {
                SWSS_LOG_DEBUG("Got element %zu %s", i, reply->element[i]->str);
                ret.emplace(reply->element[i]->str);
            }
        }
    }
    catch (const std::exception& e)
    {
        SWSS_LOG_ERROR("Caught exception while running Redis lua script: %s", e.what());
    }
    catch(...)
    {
        SWSS_LOG_ERROR("Caught exception while running Redis lua script");
    }

    return ret;
}