import ast


def redis_hgetall(duthost, db_id, key):
    """
    Get all field name and values for a given key in given redis dataabse
    :param duthost: DUT host object
    :param db_id: ID of redis database
    :param key: Redis Key
    :return: A dictionary, key is field name, value is field value
    """
    cmd = 'sonic-db-cli {} HGETALL \"{}\"'.format(db_id, key)
    output = duthost.shell(cmd)
    content = output['stdout'].strip()
    if not content:
        return {}

    return ast.literal_eval(content)