redis test questions

1. What is the Redis?

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, are 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 function, for example to do with his List 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?

redis is a memory-based high-performance database --- depends on the memory Memory.

5. What Redis stands for?

Remote Dictionary Server

6, Redis data out of what kinds of strategies?

noeviction: Returns Error When the memory limit is reached and the client will try to perform more memory command is used (most writing command, the DEL and a few exceptions) allkeys-lru: Key recovery attempt least used (LRU) 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.twemproxy, about the concept is that it is similar to a proxy approach, using methods and general redis without distinction of any kind, set up multiple instances redis after its subordinate, when used in this connection required redis place or move to an twemproxy, it will be an agent of identity receives the request and uses a consistent hash algorithm, the request is forwarded to a specific redis, the results back twemproxy. Easy to use (relatively redis simply modify the connection port), extension of the old project of choice. Problems: twemproxy pressure itself single port instance, the hash consistency after use, the number of nodes redis change when the calculated value changes, the data can not be automatically moved to the new node.

2.codis, currently the largest clustering solutions with 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.

3.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), page caching (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 large advantage Reids queue memory storage engine art to provide a list and set operations, which makes Redis can be used as a good message queue internet. 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), ranking / counter Redis of numbers increment or decrement operation to achieve very good in memory. 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 based on your user's score ascending order. If you want to return the user and the user's score, you need to perform: ZRANGE user_scores 0 10 WITHSCORESAgora Games is a good example, implemented in Ruby, its ranking is to use Redis to store data, you can see here to.

(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! (No, it's true, you can go to verify).

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 structures, and Jedis compared to function relatively simple, does not support string manipulation, Redis properties do not support ordering, transaction, plumbing, zoning and so on. 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, the expiration time and permanent Redis key, 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. **

31, Redis recycling what algorithm?

** LRU algorithm

32, Redis how to make large amounts of data insertion?

Redis2.6 start redis-cli support a new mode called new pipe mode for a number of data insertion work.

33. Why do Redis partition?

Zoning allows Redis manage more memory, Redis will be able to use all of the machine's memory. If there are no partitions, you can only use up to a machine's memory. Redis partition the computing power by simply adding computers to get increase exponentially, Redis network bandwidth will also increase computer and network cards and doubled.

34, you know what Redis partitioning implementations?

The client partition is the client had already decided which data will be stored in redis redis node or nodes from which to read. Most clients have implemented client partition. Acting partition means that the client sends a request to the agent, and the agent decide which nodes to write data or read data. The agent determines which partitioning rules Redis instance requests and returns the results to the client according to the response of Redis. memcached and redis a proxy is implemented Twemproxy routing query (Query routing) means that any client requests a random redis example, then forwards the request to the Redis Redis correct node. Redis Cluster implements a hybrid form of query routing, but not directly to the request forwarded from one node to another redis redis nodes, but with the help of the client's redirected directly to the correct node redis.

35, Redis partitions What are the disadvantages?

Operations involving multiple key usually not supported. For example, you can not find the intersection of two sets, because they could be stored in a different Redis instance (in fact this case, there are ways, but you can not use direct instruction intersection). Simultaneous operation of a plurality of key, can not be used Redis transaction. Partition size using a key, you can not use a very long key store a sorted data set (The partitioning granularity is the key, so it is not possible to shard a dataset with a single huge key like a very big sorted set). when using a partition, the data processing will be very complicated, for example, you have to collect a backup RDB / AOF files from different hosts simultaneously and Redis instances. Partition or dynamic expansion volume reduction can be complicated. Redis cluster increase in run time Redis or delete nodes, can do the greatest degree of rebalancing data transparently to the user, but some other client partitions or partitioning method proxy not support this feature. However, there is a pre-slice technology can better solve this problem.

36, Redis persistent data caching and how to do the expansion?

If Redis is used as cache usage, using consistent hashing dynamic expansion volume reduction. If Redis as a persistent storage is used, you must use a fixed keys-to-nodes mapping relationship, the number of nodes does not change once it is determined. Otherwise (That is Redis node dynamically changes) must be used for data re-balancing of a system at run-time, and the current Redis cluster can only do so.

37, Redis is distributed scale up early or late to do the re-do? why?

Since Redis is so lightweight (single instance only 1M memory), in order to prevent future expansion, the best way is to start to start more instances. Even if you have only one server, you can also outset Redis running in a distributed manner, using partitioning, start multiple instances on the same server. Setting the outset more than a few Redis instances, such as 32 or 64 examples, for most users, it can be cumbersome to operate, but to do this sacrifice is worth it in the long term. In this case, when your data is growing, requiring more Redis server, you need to do is simply Redis instance migration from one server to another server only (without regard to the issue of re-zoning). Once you add another server, you will need half your Redis instance migration from the first machine to a second machine.

38. What Twemproxy that?

Twemproxy Twitter is maintained (caching) proxy system, the ASCII protocol proxy Memcached and Redis protocol. It is a single-threaded program, using c language, and running very quickly. It is the use of open source software Apache 2.0 license. Twemproxy supports automatic partitioning, if its agents Redis when one node is unavailable, the node will be automatically excluded (which will change the mapping between the original keys-instances, so you should only be used when the Redis as cache Twemproxy). Twemproxy single point itself is not a problem, because you can start multiple Twemproxy instance, and then let your client to connect to any instance of a Twemproxy. Twemproxy Redis intermediate layer is a client and a server, which addressed partitioning should not complicated, and should be considered more reliable.

39, supports consistent hashing clients what?

Redis-rb、Predis等。

40, Redis and other key-value store What is the difference?

Redis has a more complex data structure and provide atomic operations on them, which is different from the other databases evolutionary path. Meanwhile Redis data types are based on the basic data structure transparent to the programmer, without the need for additional abstraction. Redis running in memory, but can be persisted to disk, so that when the high-speed read and write memory tradeoffs different data sets, the data should not be greater than the amount of hardware memory. Another advantage of in-memory databases are, compared to the same complex data structures, operate in a very simple memory on the disk, so you can do a lot of internal Redis highly complex matter. Meanwhile, in terms of their compact disk format to generate additional way, because they do not require random access.

41, how kind of Redis memory footprint?

Give you an example: one million key-value pair (key is 0-999999 value is the string "hello world") on my 32-bit Mac notebook with a 100MB. The same data into a key in only 16MB, which is key because there is a lot of overhead. Similar results were also executed on Memcached, Redis but relative to the cost of a little bit, because Redis will record the type of information reference count and so on. Of course, a large proportion of key-value pairs when both much better. 64-bit systems require more than 32-bit memory overhead, in particular key-value pair is small, because the system pointer 64 occupies 8 bytes. But, of course, 64-bit systems support more memory, so in order to run a more or less large Redis server requires the use of 64-bit systems.

42, what are ways to reduce memory usage Redis it?

If you are using 32-bit Redis instance, you can make good use Hash, list, sorted set, set and other types of data collection, since normally many small Key-Value can be stored in a more compact manner together.

## 43, see Redis usage and status information what order? info44, Redis memory runs out what will happen? If you reach the set limit, Redis write command returns an error message (but read command can also return to normal.) Or you can Redis as cache to use the configuration elimination mechanism, when Redis reach the memory limit may wash away the old contents. ## 45, Redis is single-threaded, how to improve the utilization of multi-core CPU? You can be deployed on the same server multiple instances of Redis, and treat them as different servers to use, at some point, in any case a server is not enough, so if you want to use multiple CPU, you can think about fragment (shard).

46, a Redis instance maximum number of keys can be stored?

List, Set, Sorted Set how many elements can be stored up to them? Theoretically Redis keys can handle up to 232, and tested in practice, stored for each instance of at least 250 million of keys. We are testing some of the larger value. Any list, set, and the sorted set can be put 232 elements. In other words, Redis available memory limit value in the system memory.

47, Redis common performance problems and solutions?

(1) Master best not to do any persistent work, such as RDB AOF memory snapshots and log files (2) if the data is more important, a Slave open AOF backup data, policy is set to sync once per second (3) In order to master-slave copy speed and stability, master and Slave in a preferably connected within the same local area network (4) to avoid increased from the library (5) on the main lot of pressure from the master database do not replicate Fig structure, unidirectional list structure more stable, namely: Master <- Slave1 <- Slave2 <- slave3 ... such a structure convenient single point of failure to solve the issue and realize the replacement of Master of Slave. If the Master hung up, you can turn immediately Slave1 do Master, the other unchanged.

48, Redis provides what kinds of persistent way?

RDB persistent manner capable of storing snapshots can be recorded .AOF persistence of your data every time the server write operations, when the server restart will re-execute these commands to restore the original data in a specified time interval, AOF command redis additional protocol to save each write operation to the end of the file .Redis also on the AOF files for background rewritten, so that the volume AOF files will not be too large. If you just want your data exists at the time the server is running, you may not use any persistent way. you can also open simultaneously two kinds of persistent way, in this case, when redis restart priority load AOF file to restore the original data, because in normal circumstances documents AOF save the file to save the data set than the RDB data set to be complete. the most important thing is to understand the RDB and AOF persistence of different ways, let us RDB persistent way to start.

49, how to choose the right way of persistence?

In general, if you want to achieve comparable PostgreSQL data security, you should use both persistent feature. If you are very concerned about your data, but you can still withstand the loss of data within a few minutes, then you can just use RDB persistence. AOF many users use only persistent, but does not recommend this approach: since the timing generating RDB Snapshot (Snapshot) is very easy database backup and recovery speed RDB data set than AOF is also faster recovery, in addition to addition to this, the use of RDB also avoid bug AOF programs mentioned earlier.

50, configuration changes will not take effect immediately restart Redis it?

For running instance, there are many configuration options can be modified through the CONFIG SET command, without any form of execution restart. Starting Redis 2.2, you can switch to a snapshot from the AOF RDB persistence or otherwise, without the need to restart Redis. Retrieval 'CONFIG GET *' command for more information. But occasionally restart is required, such as Redis program to upgrade to a new version, or when you need to modify the configuration parameters of the time is not currently supported by some CONFIG command.

Guess you like

Origin www.cnblogs.com/ouyang99-/p/12174581.html