Lock screen interview questions 100 days brush, every weekday insist on updating the interview questions. Lock screen interview app and mini program are now online, official website address: www.demosoftware.cc/#/introduct… . Has included the daily update of all the content of the interview questions, also includes features to unlock the screen to review the interview questions, daily programming questions email push and other functions. Let you in the interview one step ahead, blow the interviewer! Here’s today’s interview question:

Pros and cons of ====Redis?

Advantages:

A) High performance – Redis can support more than 100K+ read/write frequency per second.

B) Rich data types — Redis supports Strings, Lists, Hashes, Sets and Ordered Sets data types for binary cases.

C) atomic – All operations in Redis are atomic, and Redis also supports atomic execution after several operations are combined.

D) Rich features – Redis also supports publish/subscribe, notification, key expiration, etc.

Disadvantages:

A) Since it is an in-memory database, the amount of data stored by a single machine is related to the memory size of the machine itself. Although Redis has its own key expiration policy, it still needs to anticipate and save memory. If the memory grows too fast, delete data periodically.

B) If complete resynchronization is performed, the RDB file needs to be generated and transmitted, occupying CPU of the host and consuming bandwidth of the live network. Redis2.8 has partial resynchronization, but full resynchronization is possible. For example, the standby server is newly online.

C) It takes a long time to modify the configuration file, restart the system, and load data from the hard disk into the memory. In this process, Redis cannot provide services.

==== how about Redis persistence?

RDB persistence: This mechanism can generate point-in-time snapshots of data sets at specified intervals.

AOF persistence: Records all write commands executed by the server and restores the data set by re-executing these commands when the server is started. All commands in the AOF file are saved in Redis format, and new commands are appended to the end of the file. Redis can also rewrite AOF files in the background to keep them no larger than the actual size needed to hold the state of the dataset nonpersistent: data only exists when the server runs. Apply both AOF and RDB: When Redis restarts, it will use AOF files to restore datasets in preference, since AOF files usually hold more complete datasets than RDB files.

==== What are the advantages and disadvantages of RDB persistence versus AOF persistence?

Advantages and disadvantages of RDB:

Advantages: RDB is a very compact file that holds Redis data sets at a point in time. This type of file is perfect for backup: for example, you can back up an RDB file every hour for the last 24 hours and also back up an RDB file every day of the month. This way, if you run into problems, you can always revert the dataset to a different version. RDB is perfect for Disaster Recovery: it has only one file and its contents are so compact that it can be sent (encrypted) to another data center, or to Amazon S3. RDB maximizes the performance of Redis: the only thing the parent has to do to save the RDB file is fork out a child, which then handles all subsequent saves without the parent performing any disk I/O operations. RDB can recover large data sets faster than AOF.

Cons: RDB is not for you if you need to avoid losing data in the event of a server failure. Although Redis allows you to set different save points to control how often RDB files are saved, it is not an easy operation because RDB files need to hold the state of the entire data set. So you’ll probably save your RDB file at least once every 5 minutes. In this case, you could lose several minutes of data in the event of a malfunctioning outage. Each time the RDB is saved, Redis forks () out a child process that does the actual persistence. In large data sets, fork() can be time-consuming, causing the server to stop processing the client in so-and-so milliseconds; If the data set is very large and CPU time is very tight, this stop time can even take a full second.

Advantages and disadvantages of AOF.

Advantages: 1, Using AOF persistence makes Redis much more durable: You can set different fsync policies, such as no fsync, fsync every second, or fsync every time a write command is executed. The default AOF policy is fsync once per second. In this configuration, Redis still performs well and loses at most a second of data in the event of an outage (fsync is performed in background threads, so the main thread can continue to struggle to process command requests). The AOF file is an append only log file, so writes to the AOF file do not need to seek, even if the log contains incomplete commands for some reason (for example, the disk is full when writing, the write is stopped, etc.). The Redis-check-aof tool can also easily fix this problem.

2. Redis can automatically rewrite AOF in the background when AOF files become too large: the rewritten new AOF files contain the minimum set of commands needed to restore the current data set. The entire rewrite operation is absolutely safe because Redis continues to append commands to existing AOF files while creating new AOF files, and the existing AOF files will not be lost even if an outage occurs during the rewrite. Once the new AOF file is created, Redis switches from the old AOF file to the new AOF file and starts appending the new AOF file.

Disadvantages: AOF files are usually larger than RDB files for the same data set. Depending on the fsync strategy used, AOF may be slower than RDB. Fsync per second performance is still very high under normal conditions, and turning off fsync allows the AOF to be as fast as the RDB, even under high loads. However, RDB can provide more guaranteed maximum latency when handling large write loads. AOF has had a bug in the past where an AOF file could not restore the dataset as it was saved when it was reloaded due to certain commands. (For example, the blocking command BRPOPLPUSH has caused such a bug.) The test suite adds tests for this: they automatically generate random, complex data sets and reload them to make sure everything is okay. Although this kind of bug is not common in AOF files, RDB bugs are almost impossible by comparison.

====Redis single process single thread?

Redis is single-process single-thread, Redis uses queue technology to change concurrent access into serial access, eliminating the overhead of traditional database serial control.

====Redis what is the maximum amount of a string value can be stored?

512M

==== Redis expiration key deletion policy?

1, timed delete: when setting the expiration time of the key, create a timer timer. Set the timer to delete the key as soon as the key expires.

2, lazy delete: let the key expire regardless, but each time from the key space to obtain the key, check whether the obtained key is expired, if expired, delete the key; If not, the key is returned.

3, regular deletion: every once in a while the program will check the database, delete the expired key inside. It is up to the algorithm to determine how many expired keys to delete and how many databases to check.

==== What recycling strategies does Redis have?

Volatile – lRU: Selects the least recently used expires data from a set with an expiration date (server.db[I].expires)

Volatile – TTL: Selects expired data from a set (server.db[I].expires) to be discarded

Volatile -random: Selects any data from a set with an expiration date (server.db[I].expires) to be discarded

Allkeys-lru: Culls the least recently used data from the dataset (server.db[I].dict)

Allkeys-random: Random selection of data from a dataset (server.db[I].dict)

No-enviction: Data expulsion is prohibited

Note the six mechanisms here. Volatile and AllKeys specify whether to eliminate data from a set with an expiration date or from the entire set. Lru, TTL, and RANDOM are the three different elimination strategies. Plus a no-enviction never recycle policy.

Using policy rules:

1. If the data has a power-law distribution, that is, some data are accessed with high frequency and some data are accessed with low frequency, then allkeys-LRU is used

2. If the data presents equal distribution, that is, all data access frequency is the same, allkeys-random is used

====Redis synchronization mechanism understand?

Redis can use master slave synchronization and slave slave synchronization. During the first synchronization, the primary node performs a BGSave and records subsequent modifications to the memory buffer. After the synchronization is complete, the RDB file is fully synchronized to the replication node, and the replication node loads the RDB image to the memory. After the loading is complete, the master node is notified to synchronize the modified operation records to the replication node for replay.

For more interview questions or learning resources, see my home page or comments