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 Redis interview questions?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is about the content of Redis interview questions. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Redis Interview Question 1: What is Redis?

Redis is completely open source and free, complies with the BSD protocol, and is a high-performance key-value database.

Redis and other key-value caching products have three characteristics:

(1) Redis supports persistence of data, which can save data in memory to disk, and can be loaded again for use when restarting.

(2) Redis not only supports simple key-value data, but also provides storage of list, set, zset, hash and other data structures.

(3) Redis supports data backup, i.e. master-slave mode data backup.

[Recommended: Redis Video Tutorial]

Redis Advantage

(1) Very high performance- Redis can read 110000 times/s and write 81000 times/s.

(2) Rich data types- Redis supports Strings, Lists, Hashes, Sets and Ordered Sets data type operations for binary cases.

Atomic-All operations in Redis are atomic, meaning they either succeed or fail at all. Individual operations are atomic. Multiple operations also support transactions, i.e. atomicity, wrapped by MULTI and EXEC directives.

(4) Rich features- Redis also supports publish/subscribe, notifications, key expiration, etc.

How does Redis differ from other key-value stores?

Redis has more complex data structures and provides atomic operations on them, which is a different evolutionary path than other databases. Redis data types are based on basic data structures and are transparent to programmers without additional abstraction.

(2) Redis runs in memory but can persist to disk, so there is a trade-off between memory when reading and writing different data sets at high speed, because the amount of data cannot be larger than hardware memory. Another advantage in terms of in-memory databases is that they are much simpler to operate in memory than the same complex data structures on disk, so Redis can do a lot of internally complex things. At the same time, they are compact in disk format and generated additively because they do not require random access.

2. Redis data types?

A: Redis supports five data types: string, hash, list, set, and zsetsorted set.

In our actual projects, string and hash are commonly used. If you are an advanced Redis user, you need to add the following data structures HyperLogLog, Geo, Pub/Sub.

If you say you've played Redis Module, BloomFilter, RedisSearch, Redis-ML, the interviewer's eyes start to light up.

What are the benefits of using Redis?

(1) Fast, because the data exists in memory, similar to HashMap, the advantage of HashMap is that the time complexity of lookup and operation is O1)

(2) Support rich data types, support string, list, set, Zset, hash, etc.

(3) support transactions, operations are atomic, the so-called atomicity is to change the data either all executed or not executed

(4) Rich features: can be used for caching, messages, set expiration time by key, will be automatically deleted after expiration

What are the advantages of Redis over Memcached?

(1) Memcached All values are simple strings, redis as its replacement, supporting richer data classes

Redis is faster than Memcached.

Redis can persist its data

What is the difference between Memcache and Redis?

(1) Storage method Memecache stores all the data in memory, and will hang up after power failure. The data cannot exceed the memory size. Redis is partially stored on the hard disk, which ensures data persistence.

(2) Data support types Memcache support for data types is relatively simple. Redis has complex data types.

(3) The use of the underlying model is different. The underlying implementation between them and the application protocol for communication with the client are different. Redis built the VM mechanism itself directly, because ordinary system calls waste time moving and requesting system functions.

Is Redis a single-process, single-threaded system?

A: Redis is a single-process single-threaded, redis uses queue technology to turn concurrent access into serial access, eliminating the overhead of traditional database serial control.

What is the maximum storage capacity of a string type value?

Answer: 512M

8 What is the persistence mechanism of Redis? What are their strengths and weaknesses?

Redis provides two persistence mechanisms, RDB and AOF:

1. RDBRedis DataBase) Persistence method:

It refers to semi-persistent mode in the way of dataset snapshot) records all key-value pairs of redis database, writes data to a temporary file at a certain time point, and replaces the last persistent file with this temporary file after persistence, so as to achieve data recovery.

Advantages:

(1) There is only one file dump.rdb, which is easy to persist.

(2) Disaster recovery is good, a file can be saved to a safe disk.

(3) performance maximization, fork child process to complete the write operation, let the main process continue to process commands, so IO maximization. Use a separate child process for persistence, the main process will not perform any IO operations, ensuring the high performance of redis)

(4) Higher startup efficiency than AOF when the data set is large.

Disadvantages:

Data security is low. RDBs are persisted at intervals, and data loss occurs if redis fails between persistence. So it's more appropriate when the data is not rigorous.

2. AOFAppend-only file) Persistence method:

All command-line records are stored as aof files in the redis command request protocol format (fully persistent).

Advantages:

(1) Data security, aof persistence can be configured appendfsync attribute, always, every command operation is recorded in the aof file once.

(2) Write files in append mode. Even if the server goes down halfway, you can solve the data consistency problem through the redis-check-aof tool.

(3) rewrite mode of AOF mechanism. Before the AOF file is rewritten (the command will be merged and rewritten when the file is too large), you can delete some of the commands (such as flushall)

Disadvantages:

(1) AOF files are larger than RDB files and slower to recover.

(2) When the data set is large, it is less efficient than rdb startup.

9. Redis Common Performance Issues and Solutions:

(1) Master had better not write memory snapshot. If Master writes memory snapshot, save command dispatches rdbSave function, which will block the work of main thread. When snapshot is relatively large, the impact on performance is very large, and service will be suspended intermittently.

(2) If the data is more important, a Slave turns on AOF backup data, and the policy is set to synchronize one per second.

(3) For the speed of master-slave replication and the stability of connection, Master and Slave should be in the same local area network.

(4) Try to avoid adding slaves to the main library with high pressure.

(5) Master-slave replication does not use a graphical structure, but a unidirectional linked list structure is more stable, i.e.: 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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report