How to install Redis on Linux

Foreword Why do we use redis

1. Fast speed: Under normal circumstances, Redis executes commands very fast. The official figure is that the read and write performance can reach 100,000/sec.

2. Data structure server based on key-value pairs Almost all programming languages ​​provide dictionary-like functions

For example, the map in Java and the dict in Python are similar to this way of organizing data called key-value-based methods. Unlike many key-value pair databases, the value in Redis can not only be a string, but also Is the specific data structure,

This not only facilitates the development of many application scenarios, but also improves development efficiency. The full name of Redis is REmote Dictionary Server. It mainly provides five types of data structures: string, hash, list, and ordered collection. At the same time, two types of Bitmaps and HyperLogLog have evolved on the basis of strings. The magical "data structure",

And with the continuous development of LBS (Location Based Service), Redis 3.2 has added functions related to GEO (Geographic Information Positioning). In short, with the help of these data structures, developers can develop various " Interesting" application.


3. Abundant functions
In addition to five data structures, Redis also provides many additional functions:
·Provides key expiration function, which can be used to implement caching.
·Provides a publish and subscribe function, which can be used to implement a message system.
·Support Lua script function, you can use Lua to create new Redis commands.
·Provides simple transaction functions, which can guarantee transaction characteristics to a certain extent.
·Provides a pipeline (Pipeline) function, so that the client can transmit a batch of commands to
Redis at one time , reducing network overhead.

4. Simple and stable
The simplicity of Redis is mainly manifested in three aspects. First of all, the source code of Redis is very few. The code of the early version is only about 20,000 lines. After version 3.0, due to the addition of the cluster feature, the code has increased to about 50,000 lines. Compared with many NoSQL databases, the amount of code is relatively small. It means that ordinary development and operation and maintenance personnel can "see through" it. Secondly, Redis uses a single-threaded model, which
not only makes the Redis server-side processing model simple, but also makes client-side development easier. Finally, Redis does not need to rely on class libraries in the operating system (for example, Memcache needs to rely on system class libraries such as libevent), and Redis implements event processing related functions by itself.
Although Redis is very simple, it does not mean it is unstable. Taking thousands of Redis maintained by the author as an example, there has been no downtime due to Redis's own bugs.

5. Multi-language client
Redis provides a simple TCP communication protocol, many programming languages can easily access to Redis, and because Redis is widely recognized communities and major companies, so the support Redis guest
client language is also very Many, almost covering mainstream programming languages, such as Java, PHP, Python, C, C++, Nodejs, etc. [1], in Chapter 4, we will give a detailed description of the Redis client

Bright.
6. Persistence
Generally speaking, it is not safe to put data in memory. Once power failure or machine failure occurs, important data may be lost. Therefore, Redis provides two persistence methods: RDB and AOF, which can be Two strategies are used to save the data in the memory to the hard disk (as shown in Figure 1-1), which ensures the durability of the data. In Chapter 5, we will explain the persistence of Redis in detail.
Figure 1-1 Redis memory to disk persistence

7. Master-slave replication
Redis provides the replication function, which realizes multiple Redis copies of the same data (as
shown in Figure 1-2 ). The replication function is the basis of distributed Redis. In Chapter 6, we will give a detailed
description of Redis replication .

Figure 1-2 Redis master-slave replication architecture
8. High-availability and distributed
Redis from version 2.8 officially provides a high-availability implementation Redis Sentinel, which can ensure
failure detection and automatic failure transfer of Redis nodes. Redis has officially provided a distributed implementation of
Redis Cluster since version 3.0 . It is a true distributed implementation of Redis and provides high availability, read-write, and capacity
scalability.

 

 

What can redis do?


1. Cache


The caching mechanism is used in almost all large-scale websites. Proper use of caching can not only speed up data access, but also effectively reduce the pressure on back-end data sources. Redis provides
key value expiration time settings, and also provides flexible control of maximum memory and elimination strategies after memory overflow. It can be said that a reasonable cache design can escort the stability of a website. Chapter
11 will explain the design and use of the cache in detail.


2. Ranking system


The ranking system exists in almost all websites. For example, ranking based on popularity, ranking based on release time, ranking based on various complex dimensions, Redis provides a list
and ordered collection of data structures, which can be used reasonably These data structures can easily build various ranking systems.


3. Counter application

 


Counter crucial role in the site, such as video site has several players, the electricity supplier site
Views, in order to ensure real-time data, every player and browse have to do the operation plus 1, as
a large amount of concurrent fruit The performance of traditional relational data is a challenge. Redis naturally supports the counting
function and the counting performance is also very good, which can be said to be an important choice for the counter system.

 

4. Social networks

 


Like up / down, fan, mutual friend / love, push, pull down to refresh and other social networking sites is an essential function of energy, due to the social networking site traffic is usually large, and traditional relational data stored is not suitable for
this type of data, The data structure provided by Redis can implement these functions relatively easily.


5. Message Queuing System

 


The message queuing system can be said to be a necessary basic component of a large-scale website, because it has the characteristics of business decoupling and non-real-time business peak cutting. Redis provides the function of publish and subscribe and the function of blocking queue
. Although it is not powerful enough compared with professional message queue, it can basically meet the general message queue function.

 

Start installing redis

1)下载Redis指定版本的源码压缩包到当前目录。
2)解压缩Redis源码压缩包。
3)建立一个redis目录的软连接,指向redis-3.0.7。
4)进入redis目录。
5)编译(编译之前确保操作系统已经安装gcc)。
6)安装。

这里有两点要注意:
第一,第3步中建立了一个redis目录的软链接,这样做是为了不把redis目录固定在指定版本上,有利于Redis未来版本升级,算是安装软件的一种好习惯。第二,第6步中的安装是将Redis的相关运行文
件放到/usr/local/bin/下,这样就可以在任意目录下执行Redis的命令。例如安装后,可以在任何目录执行redis-cli–v查看Redis的版本

 

So we installed successfully

 

 

 

 

start up

Enter the bin directory of redis and execute ./redis-server followed by redis-conf This is the configuration file of redis

 

Guess you like

Origin blog.csdn.net/qq_39313596/article/details/115215215