Redis installation instructions (transferred and deleted)

Posted by stricks1984 on Thu, 03 Mar 2022 07:21:15 +0100


Most enterprises deploy projects based on Linux servers, and Redis official does not provide the installation package of Windows version. Therefore, in the course, we will install Redis.com based on Linux system

The Linux version selected here is CentOS 7

Redis's official website address: https://redis.io/

1. Install Redis on a single machine

1.1. Install Redis dependency

Redis is written in C language, so you need to install the gcc dependency required by redis first:

yum install -y gcc tcl

1.2. Upload and unzip the installation package

Then upload the Redis installation package provided in the pre class materials to any directory of the virtual machine:

For example, I put it in the / usr/local/src Directory:

Decompression:

tar -xzf redis-6.2.6.tar.gz

After decompression:

Enter redis Directory:

cd redis-6.2.6

Run the compile command:

make && make install

If there are no errors, the installation should be successful.

The default installation path is in / usr/local/bin directory:

This directory and the default configuration are set to environment variables, so you can run these commands in any directory. Of which:

  • Redis cli: a command line client provided by redis
  • Redis server: it is the server startup script of redis
  • Redis sentinel: it is the sentinel startup script of redis

1.3. start-up

There are many ways to start redis, for example:

  • Default startup
  • Specify configuration startup
  • Start and start automatically

1.3.1. Default startup

After installation, enter the Redis server command in any directory to start Redis:

redis-server

As shown in the figure:

This startup belongs to the foreground startup, which will block the whole session window. When the window is closed or press CTRL + C, Redis will stop. Not recommended.

1.3.2. Specify configuration startup

If you want to start redis in the background mode, you must modify the redis configuration file, which is under the redis installation package we extracted earlier (/ usr/local/src/redis-6.2.6). The name is redis conf:

Let's back up this configuration file first:

cp redis.conf redis.conf.bck

Then modify redis Some configurations in the conf file:

# The allowed address is 127.0.0.1 by default, which can only be accessed locally. If it is modified to 0.0.0.0, it can be accessed at any IP address. The production environment should not be set to 0.0.0.0
bind 0.0.0.0
# The daemon can run in the background after being modified to yes
daemonize yes 
# Password. After setting, you must enter a password to access Redis
requirepass 123321

Other common Redis configurations:

# Listening port
port 6379
# The working directory is the current directory by default, which is the command when running redis server. Log, persistence and other files will be saved in this directory
dir .
# The number of databases is set to 1, which means that only 1 library is used. By default, there are 16 libraries, numbered 0 ~ 15
databases 1
# Set the maximum memory that redis can use
maxmemory 512mb
# Log file. It is empty by default. No log is recorded. You can specify the log file name
logfile "redis.log"

Start Redis:

# Enter the redis installation directory 
cd /usr/local/src/redis-6.2.6
# start-up
redis-server redis.conf

Out of Service:

# Use Redis cli to execute the shutdown command to stop the Redis service,
# Because the password was configured before, you need to specify the password through - u
redis-cli -u 123321 shutdown

1.3.3. Start and start automatically

We can also realize self startup through configuration.

First, create a new system service file:

vi /etc/systemd/system/redis.service

The contents are as follows:

[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /usr/local/src/redis-6.2.6/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Then reload the system service:

systemctl daemon-reload

Now, we can use the following set of commands to operate redis:

# start-up
systemctl start redis
# stop it
systemctl stop redis
# restart
systemctl restart redis
# View status
systemctl status redis

Execute the following command to enable redis to start automatically:

systemctl enable redis

2.Redis client

After installing redis, we can operate redis and realize CRUD of data. Redis client is required, including:

  • Command line client
  • Graphical desktop client
  • Programming client

2.1.Redis command line client

After Redis is installed, it comes with its own command-line client: Redis cli, which is used as follows:

redis-cli [options] [commonds]

Common options are:

  • -h 127.0.0.1: Specifies the IP address of the redis node to be connected. The default is 127.0.0.1
  • -p 6379: Specifies the port of the redis node to be connected. The default is 6379
  • -a 123321: specify the access password of redis

commonds are Redis operation commands, for example:

  • ping: perform a heartbeat test with the redis server, and the server will return a pong normally

If common is not specified, you will enter the interactive console of redis cli:

2.2. Graphical desktop client

The great God on GitHub wrote Redis's graphical desktop client, address: https://github.com/uglide/RedisDesktopManager

However, the warehouse provides the source code of RedisDesktopManager and does not provide windows installation package.

The installation package can be found in the following warehouse: https://github.com/lework/RedisDesktopManager-Windows/releases

2.2.1. install

Redis's graphical desktop client can be found in the pre class materials:

After decompression, run the installer to install:

Omitted here.

After installation, find rdm.com in the installation directory Exe file:

Double click to run:

2.2.2. Establish connection

Click the connect to Redis server button in the upper left corner:

Fill in Redis service information in the pop-up window:

After clicking OK, this link will appear in the left menu:

Click to establish a connection:

Redis has 16 warehouses by default, with numbers ranging from 0 to 15 The number of warehouses can be set through the configuration file, but it does not exceed 16, and the warehouse name cannot be customized.

If you are connecting to the Redis service based on Redis cli, you can select the database through the select command:

# Select library 0
select 0

Topics: Programming compiler