Why is redis faster than mysql?

  1. Redis is based on memory storage, and MySQL is based on disk storage;
  2. Redis stores data in kv format. The time complexity is O(1), constant order, while the underlying implementation of the MySQL engine is B+Tree, and the time complexity is O(logn), logarithmic order. Redis will be a little bit faster than MySQL;
  3. MySQL data storage is stored in the table. When looking up data, you must first perform a global scan of the table or search according to the index. This involves disk search. If the disk search is searched by points, it may be faster, but sequential search is slower. ; And Redis does not need to be so troublesome, it is stored in memory, and will be directly taken out according to the location of the data in memory;
  4. Redis is a single-threaded multiplexed IO. Single-threaded avoids the overhead of thread switching, while multiplexed IO avoids the overhead of IO waiting. In a multi-core processor, the efficiency of the processor can be improved to partition the data. Then each processor processes different data;

Guess you like

Origin blog.csdn.net/qq_34663267/article/details/114552216