How to Setup Redis for Magento 2.4.3?

After we successfully installed Redis, if we run:
redis-cli

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
/usr/local/redis/bin/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

PATH=$PATH:$HOME/bin:/usr/local/redis/bin
export PATH

Save and exit.

Run:
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=127.0.0.1 –cache-backend-redis-db=0

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

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

redis-cli monitor

We have shared the method to install redis-cli for CentOS7, and Centos 8.  Next I will share how to install redis under Ubuntu 18.0.4 and Ubuntu 20.0.4:

 

First, same as CentoOS, we need to know where redis-cli is:

Run the following command, and we will find the location of the command of redis-cli
which redis-cli
/usr/local/redis/bin/redis-cli

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

How to Set and List Environment Variables in Ubuntu then?

Open the Environment Variables (profile, which is under etc folder) of Ubuntu.
sudo gedit /etc/profile

And at the end of the file, add the following 2 lines:

export REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin

 


How to set environment variable on Ubuntu

 

On Ubuntu, there are two system-wide environment variables, both files need admin or sudo to modify it.

/etc/environment – It is not a script file, purely assignment expressions, one per line.

/etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/redis/bin"

Reboot Ubuntu. OK