Magento provides command-line options to configure the Redis page and default
caching. Although you can configure caching by editing the app/etc/env.php file, the
command line is the recommended method. The command line provides validation.
Redis must be installed on your server before continuing.
Redis configuration for default caching.
Run the setup:config:set command and specify parameters for Redis configuration.
bin/magento setup:config:set --cache-backend = redis
--cache-backend-redis- < parameter >=< value >
Here are the following parameters with default values.
● --cache-backend-redis-server=127.0.0.1
Fully qualified hostname, IP address, or an absolute path to a UNIX socket. The default value of 127.0.0.1 indicates Redis is installed on the Magento server.
● --cache-backend-redis-port=6379
Redis server listen port
● --cache-backend-redis-db=0
It’s required in case you are using Redis for more than one type of cache e.g. Magento default, page cache, and session storage then you have to assign the default cache database value to 0, the page cache database value to 1, and the session storage database value to 2.
● --cache-backend-redis-password=
Configuring a Redis password enables one of its built-in security features. The password is configured in the Redis configuration file: /etc/redis/redis.conf
Example command
The following example enables Redis default caching, sets the host to 127.0.0.1, and assigns the database number to 0. Redis uses default values for all other parameters.
bin/magento setup:config:set --cache-backend=redis
--cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=0
Redis configuration for page-cache
Run the setup:config:set command and specify parameters for Redis page-cache
configuration.
bin/magento setup:config:set --page-cache = redis
--page-cache-redis- < parameter >=< value >
Here are the following parameters with default values.
● --page-cache-redis-server=127.0.0.1
Fully qualified hostname, IP address, or an absolute path to a UNIX socket. The default value of 127.0.0.1 indicates Redis is installed on the Magento server.
● --page-cache-redis-port=6379
Redis server listen port
● --page-cache-redis-db=0
It’s required in case you are using Redis for more than one type of cache e.g. Magento default, page-cache, and session storage then you have to assign the default cache database value to 0, the page-cache database value to 1, and the session storage database value to 2.
● --page-cache-redis-password=
Configuring a Redis password enables one of its built-in security features.
Example command
The following example enables Redis page caching, sets the host to 127.0.0.1, and assigns the database number to 1. All other parameters are set to the default value.
bin/magento setup:config:set --page-cache=redis
--page-cache-redis-server=127.0.0.1 --page-cache-redis-db=1
Results
After running these commands Magento adds configuration to app/etc/env.php file.

Verify Redis connection
redis-cli monitor
redis-cli ping
It monitors command logs for every processed command on Redis. And ping
command responds with PONG.
Reference Magento doc: https://devdocs.magento.com/guides/v2.3/config-guide/redis/redis-pg-cache.html