[] -Redis face questions common interview questions (b)

1. What is the Redis? It outlined the advantages and disadvantages?

Is the Key-Value Redis essentially a type of memory database, the memcached like, operates the entire database in memory to load all of them, the asynchronous operation by periodically flush the database data to be stored on the hard disk.

Because it is pure memory operation, Redis performance is very good, can handle more than 100,000 times per second read and write operations, it is known to the fastest performance of Key-Value DB.

Redis not only excellence of performance, Redis greatest charm is to support a variety of data structures stored, in addition to the maximum limit of a single value is 1GB, unlike memcached data can only be saved 1MB, so Redis can be used for many useful Features.

Let's say he's List to do with FIFO doubly linked list to achieve a lightweight, high-performance message queuing service, with his Set can do high-performance tag systems.

In addition Redis can also set expire time of deposit of the Key-Value, it can also be used as a function enhanced version of memcached to use. The main disadvantage of Redis database capacity by limiting physical memory, reading and writing massive data can not be used in high-performance, and therefore the appropriate scene Redis mainly confined to the small amount of data and high-performance computing operations.

2, Redis memcached What are the advantages compared to?

All values ​​(1) memcached are simple strings, redis as its replacement, support richer data types

(2) redis much faster than memcached

(3) redis can persist its data

3, Redis to support what kinds of data types?

String、List、Set、Sorted Set、hashes

4, Redis major consuming what physical resources?

RAM.

5. What Redis stands for?

Remote Dictionary Server。

6, Redis data out of what kinds of strategies?

noeviction: returns an error when the memory limit is reached and the client attempts to execute commands allow more memory to be used (most of the write command, but DEL and with a few exceptions)

allkeys-lru: key recovery attempts (LRU) the least used, so that the newly added data storage space.

volatile-lru: key recovery attempts (LRU) the least used, but only in the key set expired, so that the newly added data storage space.

allkeys-random: the random key so that the recovered data are newly added storage space.

volatile-random: the random key so that the recovery of the newly added data storage space, but only in the set of key expiration.

volatile-ttl: recovered in expired key set, and the survival time (TTL) shorter recovery key priority, so that the newly added data storage space.

7, Redis official Why not offer Windows version?

Because the current version of Linux has been quite stable, and a large amount of users, without having to develop windows version, but will bring compatibility issues.

8, a value of type string can store the maximum capacity is how much?

512M

9. Why Redis need to put all the data into memory?

Redis To achieve the fastest read and write speed data into memory, and by asynchronously writing data to disk.

Therefore, fast and redis data persistence features. If you do not put the data in memory, disk I / O speed to seriously affect the performance of redis.

In memory getting cheaper today, redis will become increasingly popular. If you set the maximum memory used, the data has been recorded can not continue to insert a new value after the number reached memory limit.

10, Redis cluster program should be how to do? What are the solutions?

1.codis.

Currently the most used cluster programs, basic and consistent twemproxy effect, but it supports the change in the number of nodes, the node data to restore the old to the new hash node.

2.redis cluster3.0 own cluster, characterized by his consistency hash algorithm is not distributed, but the concept of hash slots, as well as their support node settings from a node. Specifically to see the official documentation describes.

4. In the business code layer, it is from several unrelated redis example, in the code level, of the key hash calculation, then redis example operation corresponding to the data. This way hash code requires a relatively high level, considered part comprises, after node failure algorithm alternative embodiment, the shock automatic script data recovery, the monitoring of example, and the like.

11, Redis clustering scheme under what circumstances would cause the entire cluster is unavailable?

A cluster with A, B, C of the three nodes, in the absence of replication model, if the Node B fails, then the entire cluster will think that lack this range 5501-11000 slot is not available.

12, MySQL, there 2000w data, only the data stored in redis 20w, how to ensure that the data is hot data in redis?

redis memory size of the data set to rise to a certain size and they will perform data elimination strategy.

13, Redis which the appropriate scene there?

(1) the session cache (Session Cache)

The most common scenario is using Redis session cache (session cache). Redis caching session with than other storage (such as Memcached) has the advantage of: Redis provide persistence. When not strictly required to maintain a cache coherency, if the user's shopping cart information lost, most people will be unhappy, and now, they will do so?

Fortunately, with the improvement of Redis these years, it's easy to find the right document how to use Redis caching session. Even well-known business platform Magento also offers Redis plug-ins.

(2) full-page cache (FPC)

In addition to the basic session token, Redis also provides a very convenient platform for FPC. Back consistency, even restart Redis instance, because of the persistent disk, users will not see a decrease page loading speed, which is a great improvement, similar to PHP local FPC.

Magento again as an example, Magento offers a plug-in to use Redis as a full-page cache backend.

In addition, the WordPress user, Pantheon has a great plugin wp-redis, this plugin can help you with the fastest speed of loading pages you've visited.

(3) a queue

Reids a big advantage in the field memory storage engine is to provide a list and set operations, which makes Redis can serve as a good platform to use the message queue. Redis used as an operation queue, similar to native language (e.g., Python) push on the list / pop operations.

If you do a quick search for "Redis queues" in Google, you'll be able to find a large number of open source projects, the purpose of these projects is to use Redis create a very good back-end tools to meet the needs of various queues. For example, Celery has a background is to use Redis as a broker, you can go to see from here.

(4) charts / Counter

Redis digital up or down in memory operations are implemented very well. Collection (Set) and an ordered set (Sorted Set) also allows us the time to perform these operations become very simple, Redis just provide just these two data structures.

So, we need to sort the collection to get the highest ranked 10 users - what we call "user_scores", we just need to execute something like the following:

Of course, this assumes you are doing increasing user score based on your sort. If you want to return the user and the user's score, you need to perform:

ZRANGE user_scores 0 10 WITHSCORES

Agora Games is a good example, implemented in Ruby, its ranking is to use Redis to store data, you can see here.

(5) Publish / Subscribe

Last (but certainly not least) is Redis publish / subscribe functionality. Publish / Subscribe usage scenario is indeed very much. I have seen people use social networking connections, but also to build a chat system based publish / subscribe Script Triggers, and even publish Redis / subscribe functionality!

14, Redis supports Java client has what? Official recommended to use which?

Redisson, Jedis, lettuce and so on, the official recommended Redisson.

15, Redis and Redisson What is the relationship?

Redisson is an advanced distributed coordination Redis customer service side, can help users to easily achieve some Java objects (Bloom filter, BitSet, Set, SetMultimap, ScoredSortedSet, SortedSet, Map, ConcurrentMap, List, ListMultimap, Queue in a distributed environment, BlockingQueue, Deque, BlockingDeque, Semaphore, Lock, ReadWriteLock, AtomicLong, CountDownLatch, Publish / Subscribe, HyperLogLog).

16, Jedis and Redisson contrast what advantages and disadvantages?

Jedis is a Java implementation of the client Redis, the API provides more comprehensive support for Redis commands;

Redisson a distributed and scalable Java data structure, and Jedis compared to relatively simple functions, string manipulation is not supported, are not supported Redis sorting characteristics, transaction, pipelines, and other partitions. Redisson aim is to promote the separation of interest to the user Redis, thereby enabling users to focus more narrowly on business logic.

17, Redis how to set a password and verify password?

Password: config set requirepass 123456

Authorization Password: auth 123456

18, talk about the concept of Redis hash slot?

Each node of the cluster is not used Redis the hash consistency, but introduces the concept of a hash slot, 16384 clusters Redis hash slots, each key by the CRC16 checksum of modulo 16384 to determine which channel is placed, the cluster responsible for part of hash slots.

19, the main Redis cluster replication model from what?

In order to cluster remain available in case of partial failure node or most nodes can not communicate, it uses the cluster from the master copy model, each node has the N-1 replicas.

20, Redis cluster will write to lose it? why?

Redis does not guarantee strong consistency of the data, which means that in practice the cluster may be lost when operating under certain conditions.

21, between Redis cluster is how to copy?

Asynchronous Replication

22, the maximum number of cluster nodes Redis is how much?

16384.

23, how to select a database Redis cluster?

Redis database cluster currently do not select the default database at 0.

24, how to test the connectivity of Redis?

ping

25, Redis what's the use in the pipeline?

A request / response server can be realized even if the old process a new request has not been a request response. This allows you to send multiple commands to the server without waiting for a reply, and finally read the answer in one step.

This is the Pipeline (pipelining), it is a technique widely used for decades. For example, many POP3 protocol has been implemented to support this function, greatly accelerate the download new messages from the server process.

26, how to understand Redis affairs?

A transaction is a single isolation Operation: All commands are serialized transaction performed sequentially. During execution of a transaction, the command will not be sent to other client requests interrupted.

A transaction is an atomic operation: commands in the transaction are either all executed or not executed all.

27, Redis commands related to the transaction and which of?

MULTI、EXEC、DISCARD、WATCH

28, Redis key expiration time and permanent, respectively, how to set?

EXPIRE and PERSIST command.

29, Redis how to do memory optimization?

Whenever possible, use a hash table (hashes), hash table (hash table is to say less inside the store number) memory used is very small, so you should be as your data model abstraction to a hash table inside.

For instance, your web system has a user object, not to the user's name, last name, email, password, set up a separate key, but just think of all the information stored in the user to a hash table inside.

30, how Redis recovery process work?

A client is running a new command, add new data.

Redi check memory usage, if more than the limit maxmemory, the recovered according to predetermined policy.

A new command is executed, and so on.

So we continue through the memory limitations of the border, by constantly reach the border and then continue to recover back to the border.

If the result of a command resulted in large amounts of memory to be used (for example, to save a lot of intersection of the sets to a new key), it will not be long before the memory limit is beyond the memory usage.



Author: java Road to Success
link: https: //www.jianshu.com/p/36a646cef11a
Source: Jane book
Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source.

Reproduced in: https: //www.cnblogs.com/juihai/p/11079079.html

Guess you like

Origin blog.csdn.net/weixin_34104341/article/details/93609090