Redis database introduction and manual compilation and installation process

Keywords: Database Redis network SQL


This paper introduces Redis database from the origin of NoSQL, then demonstrates the process of Redis manual compilation and installation (the system version of the experimental environment is Centos7), and finally introduces the common command tools of Redis.

What is NoSQL?

NoSQL -- non relational SQL, non relational database. The storage mode, storage structure and usage scenario of non relational database are totally different. With the development of the network, the relational database has encountered related problems in dealing with massive data and highly concurrent network services:

1) Unable to meet the high concurrent read and write requirements for the database

2) Unable to meet the requirements of efficient storage and access to massive data

3) Unable to meet the high availability and high scalability of the database

The following figure shows the mind map of relational database and non relational database for reference:

Redis introduction

Redis (remote dictionary server) is an open source NoSQL database written in C language. Redis is based on memory and supports persistence. It adopts the storage form of key value (key value pair), which is an indispensable part of the current distributed architecture.

Advantages and use scenarios:

● it has a very high speed of data reading and writing. The speed of data reading can be up to 110000 times / s, and the speed of data writing can be up to 81000 times / s;
● support rich data types, not only simple key value data, but also string, lists, hashes, sets, Ordered Sets and other data type operations;
● support data persistence, which can save the data in memory in the disk, and can be loaded again for use when restarting;
● atomicity, all Redis operations are atomicity;
● support data backup, i.e. master salve mode data backup;

As a memory based database, Redis cache is one of its most common application scenarios. In addition, common application scenarios of Redis include: obtaining the latest N data operations, ranking applications, counter applications, storage relations, real-time analysis system, log recording, etc.

Redis manual compilation and installation

1. Get the installation package resource extraction and installation compilation tools
Package source: link:
Extraction code: bvdi

[root@localhost ~]# hostnamectl set-hostname redis_install_install
[root@localhost ~]# su
[root@redis_install ~]# yum install gcc gcc-c++ make -y
[root@redis_install_install ~]# ls  #Redis? Install package
anaconda-ks.cfg  initial-setup-ks.cfg  redis_install-5.0.7.tar.gz
Desktop          Music                 Templates
Documents        Pictures              Videos
Downloads        Public
[root@redis_install redis_install]# tar zxvf redis_install-5.0.7.tar.gz -C /opt #Redis? Install source package can be downloaded directly to the official website

2. Build install

[root@redis_install redis_install-5.0.7]# make  #make directly
[root@redis_install redis_install-5.0.7]#  make PREFIX=/usr/local/redis_install/ install    #Specify the redis? Install directory and install it. During the installation process, change the installation path by using make PRRFIX = install path
[root@redis_install redis_install-5.0.7]# cd /usr/local/redis_install/
[root@redis_install redis_install]# ls
[root@redis_install redis_install]# cd bin/
[root@redis_install bin]# ls  #Command tools related to redis install
redis_install-benchmark  redis_install-check-aof  redis_install-check-rdb  redis_install-cli  redis_install-sentinel  redis_install-server  #Redis? Install cli is the connection terminal

[root@redis_install bin]# cd /opt/redis_install-5.0.7/utils/    #Return to the redis? Install source package decompression directory
[root@redis_install utils]# ./     #Execute script to configure: port, profile directory, log file directory, etc
Welcome to the redis_install service installer
This script will help you easily set up a running redis_install server

Please select the redis_install port for this instance: [6379]  #Select the default port of redis? Install and enter directly
Selecting default: 6379
Please select the redis_install config file name [/etc/redis_install/6379.conf]     #Select the default profile name of redis? Install and enter directly
Selected default - /etc/redis_install/6379.conf
Please select the redis_install log file name [/var/log/redis_install_6379.log]     #Select the default redis? Install log file name and enter directly
Selected default - /var/log/redis_install_6379.log
Please select the data directory for this instance [/var/lib/redis_install/6379]    #Select the default data file of the default interface and enter directly
Selected default - /var/lib/redis_install/6379
Please select the redis_install executable path [] /usr/local/redis_install/bin/redis_install-server    #Select the path of the redis? Install executable file, which needs to be entered manually: / usr / local / redis? Install / bin / redis? Install server
Selected config:    #View configuration list
Port           : 6379
Config file    : /etc/redis_install/6379.conf
Log file       : /var/log/redis_install_6379.log
Data dir       : /var/lib/redis_install/6379
Executable     : /usr/local/redis_install/bin/redis_install-server
Cli Executable : /usr/local/redis_install/bin/redis_install-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.   After confirmation, directly enter to complete the configuration
Copied /tmp/6379.conf => /etc/init.d/redis_install_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting redis_install server...
Installation successful!

3. Optimize configuration and login

[root@redis_install utils]# ln -s /usr/local/redis_install/bin/* /usr/local/bin #Create a soft connection with the redis? Install command for system identification
[root@redis_install utils]# netstat -ntap |grep 6379
tcp        0      0*               LISTEN      26085/redis_install-server  
[root@redis_install utils]# vim /etc/redis_install/6379.conf    #Modify profile
bind   #Add native ip as listening object
[root@redis_install utils]# /etc/init.d/redis_install_6379 restart  #Restart the redis? Install Service
Stopping ...
redis_install stopped
Starting redis_install server...
[root@redis_install utils]# redis_install-cli -h -p 6379 #Successful landing> exit   #Sign out
[root@redis_install utils]#

redis common command tools

During the installation, I have checked the command tools under bin directory. This article mainly introduces two tools, redis CLI and redis benchmark.


Redis cli is a command-line tool that comes with redis. You can use redis cli to connect to the specified database. After the connection is successful, you will enter the database operating environment with the prompt of "IP address: port number >". After entering the database, users can input various operation statements to manage the database. For example, executing the ping command can detect whether the redis service is started. To exit the database operating environment, execute the "exit" or "quit" command to return the original Shell environment.

[root@redis_install ~]# redis-cli> ping

During the database connection operation, you can specify the Redis database on the remote host and command syntax through options

redis-cli -h host -p port -a password
Where - h specifies the remote host, - p specifies the port number of redis service, and - a specifies the password. If you do not add any option, connect to the redis database on this computer; if you do not set the database password, you can omit the - a option. For example, execute the following command to connect to the redis database whose host is and port is 6379, and view the statistics of redis service. 
[root@redis_install ~]# redis-cli -h -p 6379> info  #info can be followed by parameters, such as memory
# Server
redis_version:5.0.7  #redis version
......#Omit subsequent content
In the database operating environment, use the help command to get help for the command type. Among them. There are three ways to gain life
 The way to help.
Help @ < group >: get the command list in < group >
Help < command >: get help for a command
 Help < tab >: get a list of topics for possible help


Redis benchmark is an official performance testing tool for redis, which can effectively test the performance of redis services. The basic syntax is:

redis-benchmark [option] [option value]

-h:  Specify the server host name.
-p:  Specify the server port.
-s:  Specify server socket. 
-c:  Specifies the number of concurrent connections.
-n:  Specifies the number of requests.
-d:  Specified in bytes SET/GET The data size of the value.
-k:  1=keep alive 0=reconnect . 
-r:  SET/GET/INCR Random use key, SADD Use random values.
-P:  Transmission by pipeline<numreq>Request.
-q:  forced return redis.  Display only query/sec Value.
--csv:  with CSV Format output.
-l:  Generate the loop and execute the test permanently.
-t:  Run only the comma separated list of test commands.
-I:  Idle Pattern. Open only N individual idle Connect and wait.

Example demonstration:

[root@redis_install ~]# redis-benchmark -h -p 6379 -c 100 -n 100000
#Wait patiently
...... #Testing process
====== MSET (10 keys) ======
  100000 requests completed in 1.10 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

83.30% <= 1 milliseconds  #Milliseconds - milliseconds
99.76% <= 2 milliseconds
100.00% <= 2 milliseconds
90991.81 requests per second  #The number of concurrent connections per second is 90991.81 (reference, no actual production environment value)


Compared with MySQL, the manual compilation and installation of redis database is simpler, and its common tools still need to be mastered.

Posted by ramzess on Fri, 20 Mar 2020 04:20:20 -0700