In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "what are the common Redis interview questions?" in the operation of actual cases, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. What is Redis?
Redis is completely open source and free, complies with the BSD protocol, and is a high-performance key-value database.
Compared with other key-value caching products, Redis has the following three characteristics:
Redis supports data persistence. You can save the data in memory on disk and load it again when you restart it.
Redis not only supports simple key-value type data, but also provides storage of data structures such as list,set,zset,hash.
Redis supports data backup, that is, data backup in master-slave mode.
Redis advantages:
Extremely high performance: Redis can read at a speed of 110000 times per second and write at a speed of 81000 times per second.
Rich data types: Redis supports Strings,Lists,Hashes,Sets and Ordered Sets data type operations for binary cases.
Atom: all operations of Redis are atomic, meaning either successful execution or failure to execute at all. A single operation is atomic. Multiple operations also support transactions, that is, atomicity, wrapped by MULTI and EXEC instructions.
Rich features: Redis also supports publish/subscribe, notification, key expiration, and so on.
How is Redis different from other key-value stores?
Redis has more complex data structures and provides atomic operations on them, which is an evolutionary path different from other databases. The data types of Redis are based on basic data structures while being transparent to programmers without additional abstraction.
Redis runs in memory but can be persisted to disk, so memory needs to be weighed when reading and writing high-speed data sets, because the amount of data cannot be larger than hardware memory. Another advantage of in-memory databases is that compared to the same complex data structures on disk, it is very easy to operate in memory, so Redis can do a lot of things with strong internal complexity. At the same time, they are compact and appended in terms of disk format, because they do not need random access.
2. The data type of Redis?
Redis supports five data types: string (string), hash (hash), list (list), set (collection) and zsetsorted set (ordered collection).
What is commonly used in our actual project is string,hash. If you are an advanced user of Redis, you also need to add the following data structures: HyperLogLog, Geo, Pub/Sub.
If you say you've played Redis Module, like BloomFilter,RedisSearch,Redis-ML, the interviewer's eyes start to shine.
3. What are the benefits of using Redis?
Speed is fast, because the data is stored in memory, the advantage similar to HashMap,HashMap is that the time complexity of search and operation is O1)
Support rich data types, support string,list,set,Zset,hash, etc.
Transactions are supported and operations are atomic. the so-called atomicity is that changes to data are either performed or not performed at all.
Rich features, can be used for caching, messages, press key to set expiration time, after expiration will be automatically deleted
4. What are the advantages of Redis over Memcached?
All values of Memcached are simple strings, and Redis, as its replacement, supports richer data classes.
Redis is much faster than Memcached.
Redis can persist its data
5. What are the differences between Memcache and Redis?
Storage mode Memecache stores all the data in memory and will hang up when the power is off. The data cannot exceed the memory size. Part of the Redis is stored on the hard disk, which ensures the persistence of the data.
The data support type Memcache is relatively simple to support data types. Redis has complex data types.
Using the underlying model, the underlying implementation between them and the application protocol for communicating with the client are different. Redis directly builds its own VM mechanism, because the general system calls system functions, it will waste a certain amount of time to move and request.
6. Is Redis single process and single thread?
Redis is single-process and single-threaded. Redis uses queue technology to change concurrent access into serial access, which eliminates the overhead of traditional database serial control.
7. What is the maximum capacity of smart storage of a string type?
512M .
8. What is the persistence mechanism of Redis? Their respective advantages and disadvantages?
Redis provides two persistence mechanisms: RDB and AOF:
RDB (Redis DataBase) persistence method: the semi-persistent mode records all key-value pairs of the Redis database in the way of dataset snapshot, and writes the data to a temporary file at a certain time. After the persistence is completed, the last persisted file is replaced with this temporary file to achieve data recovery.
Advantages:
There is only one file dump.rdb, which is convenient for persistence.
Disaster tolerance is good, a file can be saved to a secure disk.
Performance maximization, the fork child process to complete the write operation, let the main process continue to process commands, so IO is maximized. Using a single child process for persistence, the main process will not do any IO operation, ensuring the high performance of Redis.
The startup efficiency is higher than that of AOF when the dataset is large.
Disadvantages: low data security. RDB is persisted at intervals. If Redis fails during persistence, data loss will occur. So this method is more suitable when the data requirements are not strict.
AOF (Append-only file) persistence mode: means that all command line records are fully persisted and stored as aof files in the format of the Redis command request protocol.
Advantages:
Data security, aof persistence can configure the appendfsync attribute, there is always, every command operation is recorded in the aof file.
By writing files in append mode, even if the server goes down, the data consistency problem can be solved through the redis-check-aof tool.
The rewrite mode of the AOF mechanism. Before the AOF file is rewrite (commands will be merged and rewritten when the file is too large), you can delete some of the commands (such as misoperated flushall).
Disadvantages:
AOF files are larger and slower to recover than RDB files.
When the dataset is large, it is less efficient to start than RDB.
9. Common performance problems and solutions of Redis
Master is best not to write memory snapshots. If Master writes memory snapshots, the save command dispatches the rdbSave function, 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 the service.
If the data is important, a Slave enables AOF to back up data, and the policy is set to synchronize one per second.
For the speed of master-slave replication and the stability of the connection, Master and Slave are better located in the same local area network.
Try to avoid adding slaves to the stressful main library.
Master-slave replication does not use graphic structure, but one-way linked list structure is more stable, that is, Master
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.