redis01: simple introduction and installation of redis

One: What is redis?
1. Redis is an open source, low-level support network written in C language, memory-based, distributed, optional persistent key-value storage database , belonging to nosql (Not The KV key value type in Only Sql) is currently one of the most popular NoSql databases, and it is also called a data structure server.
2. It supports multiple types of data structures, such as strings, hashes, lists, sets, and sorted sets. Redis has built-in replication, LUA scripting (Lua scripting), LRU driven events (LRU eviction), transactions (transactions) and different levels of disk persistence (persistence), and provide high availability (high availability) through Redis sentinel and automatic partitioning (Cluster) .
3. For more details, please visit redis Chinese website
redis official website

Two: the advantages and disadvantages of redis

advantage Disadvantage
Pure memory operation performance is extremely high, read and write speed can reach 11/8w times/s The capacity is limited by physical memory and cannot be used for high-performance reading and writing of massive data
Rich data types-Redis supports Strings, Lists, Hashes, Sets and Ordered Sets data type operations in binary cases Cache and database double write consistency problem
All Redis operations are atomic, and Redis also supports atomic execution of several operations after they are combined. There are cache avalanche and breakdown problems
Persistence: The data is updated using Copy-on-write technology, which can be saved to disk asynchronously. There are two main strategies, one is based on time, and the other is based on statement appending (aof)

Three: Redis in actual application scenarios

1. Cached data: The most commonly used data is often referred to as hot data for data that needs to be queried frequently and changes infrequently.

2. Message queue: equivalent to a message subscription system, such as ActiveMQ and RocketMQ. If you have higher data consistency requirements, it is still recommended to use MQ)

3. Hot data: For example, real-time hotspots on news websites, hot searches on Weibo, etc., need to be updated frequently. When the total amount of client data is relatively large, querying directly from the database will affect performance, so redis is used as a cache in front of the database.

Four: Redis installation and configuration
1. Upload the redis installation package and unzip it to the /opt/module directory, here I am using version 4.0.2 of redis, download link -> click me in

tar -zxvf redis-4.0.2.tar.gz -C /opt/module/

2. Install C language compilation environment

yum install -y gcc-c++

3. Modify the installation location, enter the decompression directory of Redis and execute vi src/Makefile ( note that the name is not changed first, and the subsequent decompression will directly generate a redis directory under /opt/module ), and change the value of PREFIX? to /opt /module/redis, here you can also customize the directory

Insert picture description here

Insert picture description here

4. Compile and install in the /opt/module/redis-4.0.2 directory. After executing the two commands of make and make install, you will find that the redis directory is automatically created for us under /opt/module.

Insert picture description here

5. Copy the configuration file to the current directory and modify the content of the file, execute under /opt/module/redis

cp /opt/module/redis-4.0.2/redis.conf ./

This file needs to be modified in three places (logfile and dir should be modified according to your own redis installation directory)

daemonize yes #Background start 136 lines

logfile /opt/module/redis/logs 171行

dir / opt / module / redis 263 行

Note: The file /opt/module/redis/logs needs to be created in advance

6.Start redis and verify login. If pong appears, it means success.

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44080445/article/details/114104050