Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Advanced features of Redis

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "the advanced features of Redis". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the advanced features of Redis.

Application scenario

Caching system: used to alleviate the high concurrency pressure of database

Counter: number of retweets, comments, fans, followers, etc. used for social networks using Redis atomic operations.

Ranking: using zset data structure to calculate the ranking

Real-time system: use the function of Redis bitmap to realize Bloom filter, and then realize the spam processing system.

Message queuing: using list data structure, message publisher push data, multiple message subscribers provide simple message queuing capabilities by blocking thread pop data

The reason why it is simple is that Redis officially does not provide a reliable consumption / release mechanism; it needs to implement the functions of mq such as failover, queue persistence, queue monitoring and flow control.

Advanced features slow query

The slow query only records the time count of Redis in processing storage (the 3 steps in the figure), and does not include network communication time and queue time, so the client timeout analysis should integrate each factor.

Note:

Slow query save quantity parameters should not be set too small, and it is best to persist slow query records on a regular basis to facilitate historical problems.

Pipline

Pipline is used to process a large number of Redis requests asynchronously.

Note:

A large number of tasks need to be divided into multiple pipline to operate (otherwise, the network and wait times are under pressure).

Pipline can only act on one Redis node at a time.

M operations (instructions similar to mget,mset) are atomic operations and the latter are not compared to pipline. Redis splits a pipeline with a lot of commands into several subcommands.

Publish and subscribe

Redis publish subscription (pub/sub) is a mode of message communication: the sender (pub) sends the message and the subscriber (sub) receives the message.

Note:

Redis cannot stack messages (new subscribers cannot get historical subscription messages)

Bitmap

The binary (ASCII code) corresponding to the string big is shown in the figure, and bitmap can directly manipulate the bits. Using each digit to represent a user or state saves 32 times the memory space compared to the int data structure.

Note:

Bitmap is not suitable for all scenarios to replace conventional data storage.

Bit is of string type and can only be stored in 512MB at most

Note that the setbit function will automatically fill bits, so the production environment should pay attention to the offset of setbit, which may be time-consuming.

Hyperloglog

Based on the HyperLogLog algorithm, it is realized to complete the independent quantity statistics with minimal space, and the type essence is string.

Note:

There is no guarantee that the data are completely correct. The official website states that the error rate is 0.81%.

Unable to get a single piece of data

GEO

GEO (Geographic Information Positioning) is a function released by the Redis3.2 version, which stores longitude and latitude, calculates the distance between two places, calculates the range, etc., and the type is essentially zset.

Redis-sentinel

Redis Sentinel is a feature released by the Redis2.8 version, which solves the pain points such as failover of Redis clusters and supports high availability.

Redis-cluster

Redis cluster is a feature released by the Redis3.0 version and supports distributed

At this point, I believe that you have a deeper understanding of the "advanced features of Redis", you might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report