How to set redirect url in Magento 2?

In Magento 2, You can redirect to any link or forcefully redirect to any link by Magento\Framework\Controller\Result\RedirectFactory object.

Using setUrl($url) -> You need to pass link as parameter for redirect
Using setPath($path) -> You need to pass path(action URL) as parameter

1. Using a direct path, you need to pass the action URL in a setPath() method.

Redirect to the cart page,  Pass action path as checkout/cart,
Redirect to contact page, the parameter is contact only
To Redirect to a login page, a parameter is customer/account/login

2. Pass Query string, Add Second Argument as a Query string array to use custom query string in URL.

You can redirect to any link by direct URL using below way,

3. Full URL redirect with Magento,

You need to pass the full URL for a redirect to a specific link in Magento 2 in the setUrl method.