How to Setup Redis for Magento 2.4?

After we successfully installed Redis, if we run:

We will get the following errors:
-bash: redis-cli: command not found

Run the following command, and we will find the location of the command of redis-cli
which redis-cli

Just add ‘/usr/local/redis/bin’ to Environment Variables in Linux

How to Set and List Environment Variables in Linux?

echo $PATH

This command will list Environment Variables in Linux.

How to add ‘/usr/local/redis/bin’ to Environment Variables in Linux, then?

#vi ~/.bash_profile

export PATH

Save and exit.

source ~/.bash_profile

The newly added Environment Variable will be active right away.

Now we can run redis-cli successfully.

Use Redis for the Magento page and default cache

bin/magento setup:config:set –cache-backend=redis –cache-backend-redis-server= –cache-backend-redis-db=0

bin/magento setup:config:set –page-cache=redis –page-cache-redis-server= –page-cache-redis-db=1

Redis monitor command
In a command prompt on the server on which Redis is running, enter:

redis-cli monitor