In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In order to solve the problem of how to achieve high availability distribution in Redis, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Slow query
Action
Log the statements whose query time exceeds a certain limit, and find the command of the bottleneck in the system.
Lifecycle of client request
There are two points:
1. Slow query occurs in the third stage, and the judgment is based on the length of execution.
two。 Client timeout is not necessarily a slow query (all four steps are possible), but slow query is a possible factor in client timeout
Two configurations
Config get slowlog-max-len=128 FIFO queues are usually set to 1000, fixed length and saved in memory
Config get slowlog-log-slower-than=10000 slow query threshold (in microseconds), i.e. 10ms, which is usually set to 1ms
= 0, that is, record all commands (view the time taken by the command), 50s
Use pipeline,1w hset-> 0.7s
Suggestions for use:
Pay attention to the amount of data carried by pipeline each time
Pipeline can only act on one redis node at a time
The difference between M operation and pipeline
4.3 publish and subscribe
Role: publisher subscriber channel
Subscribers can subscribe to multiple channels, but cannot receive pre-subscription messages
Command
Subscribe channel [channel...] Subscribe to information on one or more channels
Publish channel message information is sent to the specified channel
Unsubscribe [channel [channel...]] Means to unsubscribe from a given channel
Redis can be used not only as a cache server, but also as a message queue. Its list type is inherently supported as a message queue.
The message queue needs to be robbed, such as red packets.
Publish and subscribe, such as announcements.
4.4 Bitmap bitmap
Function: a solution to reduce memory
Command
Setbit key offset value sets the specified position offset to 0can1.
Getbit key offset gets the value of the location
Bitcount key [start end] gets the number of specified range values of 1. If not specified, it is all.
Bitop op destkey key [key...] Do multiple Bitmap and (intersection), or (union), not (non), xor (XOR), and save the results in destkey
Within the calculation range of bitpos key targetBit [start] [end], the offset is equal to targetBit, and the first position, if not specified, is all.
Actual combat: independent user statistics
100 million users, 5500 independent, using the difference between set and Bitmap
Only 100000 unique users
Use experience
Type=string, maximum 512MB
Pay attention to the offset in setbit, which may be time consuming
Bitmaps are not absolutely good.
4.5 HyperLogLog
Action
Minimal space completes independent data statistics, which is used to do cardinality statistics (non-repetitive element statistics). The advantage of HyperLogLog is that when the number or volume of input elements is very large, the space needed to calculate the cardinality is always fixed and small, and it is essentially a string.
Command
Pfadd key element [element...] Add the specified element to the HyperLogLog
Pfcount key [key...] Returns the cardinality estimate of a given HyperLogLog
Pfmerge destkey sourcekey [sourcekey...] Merge multiple HyperLogLog into a single HyperLogLog
Use experience
Whether errors can be tolerated or not, the cardinality estimation is to quickly calculate the cardinality within the acceptable range of errors.
Do you need one-on-one data
4.6 GEO Geographic Information
Action
Used to store longitude and latitude, calculate the distance between two places, range calculation, etc., in fact, the zset type implementation
Command
Geoadd key Longitude longitude Latitude latitude City member add Geographic location Information
Geopos key member acquires geolocation information
Geodist key member1 member2 [unit] acquires the distance between the two places in m, km, mi (miles), ft (ruler)
This is the answer to the question about how to achieve high availability distribution in Redis. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.