(Redis): Data type practice case

table of Contents

Data type practice case

Solution list

 

Data type practice case

Business scene
  • Semantic recognition and automatic dialogue in the field of artificial intelligence will be important technologies in the future service industry robot answering call system. Baidu's self-developed user evaluation semantic recognition service is free and open to enterprises for trial, while training Baidu's own model. The rate of trial users’ behavior is now limited, and each user is limited to 10 calls per minute.

solution
  • Design a counter to record the number of calls to control the number of business executions. Use the user id as the key and the number of uses as the value
  • Get the number of times before calling to determine whether it exceeds the limit
    • If the number of times is not exceeded, the count of each call is +1
    • Business call failed, count -1
  • Set the life cycle of the counter to a specified cycle, such as 1 second/minute, and automatically clear the number of uses in the cycle

Example

  • Solution improvement

  • Cancel the determination of the maximum value, use the incr operation to exceed the maximum value and throw an exception instead of determining whether it is greater than the maximum value
  • Determine whether it is nil,
  • If yes, set to Max-time
    • If not, count +1
    • Business call failed, count -1
  • When an exception is encountered, the + operation exceeds the upper limit, which is regarded as the upper limit

Example

Business scene
  • Procedure used in micro-channel, micro-letters when receiving a message, the default top most recently received message, when a plurality of friends and concerns simultaneously send subscription number when sending a message, the ranking will not stop alternately. You can also set important conversations to the top. Once the user is offline, when opening WeChat again , in what order should the messages be displayed?

solution
  • Rely on the order of the data in the list to manage messages, and use the list structure as a stack
  • Create separate lists for sticky and normal conversations to manage separately
  • When a user message is received in a list, the id of the message sender is added to the list from one side of the list (the left side is set here)
  • If multiple messages sent by the same id are repeatedly pushed onto the stack, there will be problems. Before being pushed onto the stack, regardless of whether there is a message corresponding to the current id, delete the corresponding id first
  • When pushing messages, push the top session list first, then push the normal session list, and the completed list will clear all data
  • The number of messages, that is, the number of WeChat user conversations is recorded separately using the idea of ​​a counter, and is updated synchronously with the list operation

Example

Solution list

Refer to the business scenarios of the previous sections

  • Tips 1: redis is used to control the primary key id of the database table, provide a generation strategy for the primary key of the database table, and ensure the uniqueness of the primary key of the database table
  • Tips 2: Redis controls the life cycle of data, controls business behaviors through whether the data is invalid, and applies to all operations with time-limited control
  • Tips 3: Redis is applied to various structured and unstructured high-temperature data access acceleration
  • Tips 4: Redis is used in shopping cart data storage design
  • Tips 5: Redis is used in data storage design for panic buying, limited purchases, limited distribution of coupons, activation codes, etc.
  • Tips 6: redis is applied to data control with operation sequence
  • Tips 7: redis applied to the latest news display
  • Tips 8: Redis is used for random recommendation information retrieval, such as hot playlist recommendation, hot news recommendation, hot travel routes, application APP recommendation, big V recommendation, etc.
  • Tips 9: redis is applied to related search of similar information, second degree related search, deep related search
  • Tips 10: redis is applied to the merge and intersection operations of the same type of unique data
  • Tips 11: redis is applied to fast deduplication of the same type of data
  • Tips 12: Redis is used for service control based on blacklist and whitelist settings
  • Tips 13: redis is applied to the ranking corresponding to the counter combination sorting function
  • Tips 14: redis is used for timing task execution sequence management or task expiration management
  • Tips 15: redis is applied to timely task/message queue execution management
  • Tips 16: redis is applied to the service control of pay-per-view settlement
  • Tips 17: redis is applied to data operations based on time sequence, without paying attention to specific time

Guess you like

Origin blog.csdn.net/baidu_41388533/article/details/108922000