string RedisReply::to_string()

in common/redisreply.cpp [279:309]


string RedisReply::to_string(redisReply *reply, string command)
{
    /*
        Response format need keep as same as redis-py, redis-py using a command to result type mapping to convert result:
            https://github.com/redis/redis-py/blob/bedf3c82a55b4b67eed93f686cb17e82f7ab19cd/redis/client.py#L682
        Redis command result type can be found here:
            https://redis.io/commands/
        Only commands used by scripts in sonic repos are supported by these method.
        For example: 'Info' command not used by any sonic scripts, so the output format will different with redis-py.
    */
    switch(reply->type)
    {
    case REDIS_REPLY_INTEGER:
        return formatReply(command, reply->integer);

    case REDIS_REPLY_STRING:
    case REDIS_REPLY_ERROR:
    case REDIS_REPLY_STATUS:
    case REDIS_REPLY_NIL:
        return formatReply(command, reply->str, reply->len);

    case REDIS_REPLY_ARRAY:
    {
        return formatReply(command, reply->element, reply->elements);
    }

    default:
        SWSS_LOG_ERROR("invalid type %d for message", reply->type);
        return string();
    }
}