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

What are the frequently asked questions in Redis interview?

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

Share

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

This article mainly introduces "what are the frequently asked questions in the Redis interview". In the daily operation, I believe many people have doubts about the frequently asked questions in the Redis interview. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "what are the frequently asked questions in the Redis interview?" Next, please follow the editor to study!

The difference between Redis and Memcached

Storage mode

Memecache stores all the data in memory and will hang up after a power outage. The data cannot exceed the memory size. Memcached itself is a server designed for caching, so the persistence of the data is not considered.

Some of the Redis is stored on the hard disk, which ensures the persistence of the data. It can be restored after a power outage.

Data support type

Memcache's support for data types is relatively simple. > > Redis has five data types.

Thread

Memecache high-performance distributed memory cache server, because redis only uses a single core, while memcached can use multiple cores

Value Siz

Redis can reach 1GB at most, while memcache only has 1MB

Why is the redis single-threaded model so efficient?

Pure memory operation

The core is IO multiplexing mechanism based on non-blocking

On the contrary, single thread avoids the problem of frequent context switching of multiple threads.

Officially, QPS can reach 10W/s.

Redis cache avalanche

Problem: at present, the e-commerce home page and hot data will be done. A cache is a fixed-time task to refresh, or if you can't find it, check the database and update it. There is a problem with scheduled task refresh. If all redis caches expire at the same time, then the Singles' Day flash sale activity will cause all requests from the front end to be called directly to the DB. For example, if you overhang a library of user services, almost all the interfaces of other libraries that depend on it will report an error. If you do not make a circuit breaker and other strategies, you will basically hang up a rhythm in an instant.

Solution: when storing data in bulk to Redis, add a random value to the failure time of each Key.

SetRedis (Key,value,time + Math.random () * 10000)

Redis cache penetration, cache breakdown

Cache traversal: when there is no data in the cache and database, and users keep making requests, the id of our database has been increased since 1, such as data with an id value of-1 or id with a very large non-existent data. At this time, the user is likely to be an attacker, and the attack will lead to excessive pressure on the database and seriously destroy the database.

Solution: add verification in the interface layer, such as user authentication verification, parameter verification, illegal parameters directly code Return, such as: id for basic verification, id

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