In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. What is Redis? * * what are the usage scenarios? **
Let's first understand the classical CAP theory:
Consistency: refers to consistency at the data level.
Availability: refers to availability at the system level.
Fault tolerance: refers to the fault tolerance from the network level.
The database is gradually differentiated from relational database to different fields and different levels. With the emergence of the scenario of reading more and writing less, the time of reading data becomes slower. in order to improve performance, database caching technology appears to separate the reading of the database. In the era of web2.0, the productivity of netizens has greatly increased, and the total amount of storage is also increasing. At present, it is still the mode of reading more and writing less. The original cache technology obviously can not meet the pressure of writing. Therefore, there are sub-databases and tables to achieve the separation of reading and writing. One of the more commonly used caching techniques is to use Redis for caching.
What is Redis?
Redis is a memory-based and persistent key-value NoSQL database, in which each key and value is represented by objects and is characterized by multiple data types, persistence, and master-slave synchronization.
Similar to Memcached, it supports relatively more value types to be stored, including string (string), list (linked list), set (collection), and zset (ordered collection). These data types support push/pop, add/remove, and take intersection union and difference sets, and richer operations, and these operations are atomic.
On this basis, redis supports a variety of different sorting methods. Like memcached, data is cached in memory for efficiency. The difference is that redis will periodically use RDB snapshots to write updated data to disk or use MySQL-like AOF log to write modification operations to additional record files, and on this basis to achieve master-slave (master-slave) synchronization. Redis supports synchronizing data to multiple slave databases, which is very useful for improving read performance.
Redis3.0 version allows a single point of failure, it has no central node, each node has the same status, and has good expansibility. Binary communication is used between nodes, and ascII protocol is used between nodes and clients.
To sum up, Redis can be used for caching, database, and message middleware.
Redis usage scenarios:
Record the number of likes, clicks and comments on posts
Cache recent hot posts
Cache article details
Record user session information.
2. What are the functions of Redis?
Data caching function
The function of distributed lock
Support for data persistence
Support transaction
Support for message queuing
3. What's the difference between Redis and memcache?
Storage methods are different: memcache stores all the data in memory and will hang up after a power outage, and the data cannot exceed the memory size; part of the Redis is stored on the hard disk, which ensures the persistence of the data.
Data support types: memcache supports relatively simple data types; Redis has complex data types.
Using the underlying model is different: the underlying implementation between them, and the application protocol for communicating with the client is different, Redis built its own vm mechanism, because the general system calls system functions, it will waste a certain amount of time to move and request.
Value values vary: Redis can reach a maximum of 1GB Redis memcache only 1mb.
4. Why is Redis single-threaded?
Because cpu is not the bottleneck of Redis, the bottleneck of Redis is most likely to be machine memory or network bandwidth. Since single-threading is easy to implement and cpu will not be a bottleneck, it makes sense to adopt a single-threaded solution.
With regard to the performance of Redis, it is also available on the official website, and ordinary laptops can easily handle hundreds of thousands of requests per second.
And single-threading does not mean slow nginx and nodejs are also representatives of high-performance single-threading.
5. What is cache traversal? * * how to solve the problem? **
Cache traversal: refers to querying a data that must not exist. Because the cache misses, it needs to be queried from the database, and if the data cannot be found, it will not be written to the cache. This will cause the non-existent data to be queried to the database every time, causing cache penetration.
Solution: the simplest and most crude method if the data returned by a query is empty (whether the data does not exist or a system failure), we cache the empty result, but its expiration time will be very short, up to five minutes.
6. What are the data types supported by Redis?
Data types supported by Redis: string (string), list (list), hash (dictionary), set (collection), zset (ordered collection).
7. What are the Java clients supported by Redis?
Supported Java clients include Redisson, jedis, lettuce, and so on.
8. What are the differences between jedis and Redisson?
Jedis: provides more comprehensive support for Redis commands.
Redisson: implements a distributed and extensible Java data structure. Compared with jedis, the function of Redisson is relatively simple, and it does not support Redis features such as sorting, transaction, pipeline, partition and so on.
9. How to ensure the consistency of cache and database data?
Set the expiration time of cache reasonably.
To update Redis synchronously when adding, changing and deleting databases, we can use transaction mechanism to ensure data consistency.
10. How many ways are there to persist Redis?
There are two ways to persist Redis, or there are two strategies:
RDB (Redis Database): snapshot storage of your data at specified intervals.
AOF (Append Only File): every write command received is appended to the file through the write function.
11. How does Redis implement distributed locks?
Redis distributed lock actually occupies a "pit" in the system, and when other programs also occupy a "pit", it can continue to execute if it is successfully occupied, and if it fails, it can only give up or try again later.
Occupy pits generally use the setnx (set if not exists) instruction, which is only allowed to be occupied by one program, and the lock is released by calling del after use.
12. What are the drawbacks of Redis distributed locks?
Redis distributed lock can not solve the problem of timeout, distributed lock has a timeout, if the execution of the program exceeds the timeout of the lock, there will be a problem.
13. How does Redis optimize memory?
Try to use the Redis hash table and store the relevant information in the hash table instead of storing each field separately, which can effectively reduce memory usage. For example, the user objects of the Web system should be stored in a hash table and then stored in Redis as a whole, instead of setting key for storage of the user's name, age, password, mailbox and other fields.
14. What are the Redis phase-out strategies?
Volatile-lru: from a dataset with an expiration time set (server. Db [i]. Expires) select the most recently used data to be eliminated.
Volatile-ttl: from a dataset with an expiration time set (server. Db [i]. Expires) to select the data that will expire.
Volatile-random: from a dataset with an expiration time set (server. Db [i]. Expires) any choice of data is eliminated.
Allkeys-lru: from the dataset (server. Db [i]. Dict) select the most recently used data to be eliminated.
Allkeys-random: from the dataset (server. Db [i]. Dict) any choice of data is eliminated.
No-enviction (eviction): data expulsion is prohibited.
15. What are the common performance problems with Redis? * * how to solve the problem? **
The master server writes memory snapshots, which will block the work of the main thread. When the snapshot is relatively large, it will have a great impact on performance and will intermittently suspend service, so it is best not to write memory snapshots on the master server.
Due to the performance problem of Redis master-slave replication, for the speed of master-slave replication and the stability of connection, the master-slave library should be in the same local area network.
Conclusion
Encourage yourself and encourage each other with these words. The harder you work, the luckier you are. If you are not the official second generation, the rich second generation or the red second generation, then please remember: diligence is the only shortcut to change your destiny.
You are welcome to leave your views in the message area and discuss and improve together. If today's article gives you new inspiration and a new understanding of the improvement of learning ability, please share it with more people.
Readers are welcome to join the programmer * * knowledge wharf * * technology group and reply "add group" in the official account background.
Cdn.xitu.io/2019/10/2/16d8a808b767b831?imageView2/0/w/1280/h/960/format/webp/ignore-error/1 ">
Guess you still want to see it.
1. What is the purpose of the jvm tuning always asked in the interview? 2. What kind of career plan should a programmer have? It's worth thinking about! 3. 3 minutes of technical information per day | interview questions + answers | jvm (1) 4. 3 minutes daily technical practical information | interview questions + answers | jvm (2)
Follow "programmer knowledge Wharf" and watch more wonderful content.
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.