The eight characteristics (advantages) of Redis and its usage scenarios

Eight characteristics of Redis (advantages)

Fast
  Speaking Redis faster, everyone's first reaction must be a memory read, that's for sure, but only if the interview when it comes to this point, it is still not enough, there are at least three things to supplement:

Redis is implemented in C language, and it is well known that C language is the programming language "closest" to the operating system, and its fast execution speed
Redis uses a single-threaded architecture (this is easy to forget, but it is the most important feature of Redis) To avoid the problem of multi-threaded resource competition,
Redis' source code is very streamlined. It can be said that it is a code-
based server that combines performance and elegance .
  Redis's entire process is Remote Dictionary Server, which is a collection of five data structures: strings , Lists, hashes, collections, ordered collections, it can be said that the five data structures are all around the form of key-value, and value can not only be a value, but also a specific data structure, which gives Redis a powerful Changeability and flexibility.

Rich functions
  In addition to the powerful data structure, the other is the rich functions provided by Redis:

Provides the key expiration function, which can be used to implement the cache
provides a publish and subscribe function, can be applied to the message queue, such as celery
support lua script function, when you think Redis command implementation function is not enough, you can use lua to create new The function
provides a simple transaction function, but it cannot support rollback, but it can also maintain the transaction feature to a certain extent. The
pipeline function is provided, so that the client can io multiple commands at once, reducing the network overhead.
Simple and stable
  Redis The performance is simple in two aspects. On the one hand, the source code was only 30,000 lines before the 3.0 version, and the code was added to 50,000 lines after the cluster was added in the latter 3.0. The source code of 50,000 lines is for developers to understand and master it. It is not so difficult; on the other hand, Redis is a single-threaded structure, which makes Redis's server-side processing model simple and client-side development also simple.
  Although Redis has less code and is single-threaded, it is very stable and rarely crashes due to its own bugs.

There are many client languages.
  Redis is basically as famous as MySQL. There are too many application scenarios and too many supported languages. Common ones are: java jedis, Python redis, PHP, C, C ++, etc.

Persistent
  Redis also supports two methods of persistence, that is, the method of writing data to disk, RDB and AOF, the two methods have their own pros and cons, and they are not described in detail here.

Master-slave replication
  The master-slave replication and cluster functions of the database are very important. It can not affect the use of the client after Redis hangs abnormally, and Redis also supports the master-slave replication function.

Redis master-slave replication architecture

 

 

 

 

Highly available and distributed

  Redis provides Redis Sentinel with high availability since version 2.8, which is Redis' "sentinel mechanism", which can ensure fault discovery and automatic transfer of Redis nodes, which realizes the powerful distributed function of Redis.

Redis application scenarios

Cache
  caching can be said to be one of the most commonly used functions of Redis. A reasonable cache can not only speed up the speed of access, but also reduce the pressure on the back end (usually the pressure of MySQL). It can be said that a reasonable cache can greatly improve the performance of the website.

The leaderboard system can
  make a leaderboard system by using the characteristics of Redis lists and ordered collections. The leaderboard system is currently indispensable in malls, news, blogs, etc.

Counter application The application of
  counter is basically the same as the leaderboard system, which is a common demand of most websites, such as the playback count of video websites, the number of views of e-commerce websites, etc., but these numbers are generally huge. If stored in a relational database, The challenge to MySQL or other relational databases is still great, and Redis can basically be said to naturally support counter applications.

The message queue system
  Redis supports the functions of a publish and subscribe system and a blocking queue. It can serve as a general message queue function. Although it has advantages compared with professional message queue MQ such as RebbitMQ, it is basically enough, such as celery's asynchronous model. Redis is also one of the 2 types of queues officially designated by Celery.

Social Networks
  For social networks, the general user volume is extremely large. At this time, the relational database is stretched. For example, it is a bit like, like, follow, push and other functions. With Redis, these functions can be more easily achieved.

Guess you like

Origin www.cnblogs.com/weigy/p/12677449.html