In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how to use the info command in Redis. It is very detailed and has a certain reference value. Friends who are interested must finish it!
Redis is an open source, memory-based, optional persistent key-value pair storage database written in ANSI C. it is widely used in large e-commerce websites, video websites and game applications. It can effectively reduce database disk IO, improve data query efficiency, reduce the workload of management and maintenance, and reduce database storage costs. It is an important supplement to the traditional disk database and has become one of the indispensable basic services for Internet applications, especially for Internet applications that support high concurrent access. Its main advantages are as follows:
First of all, the performance of ● is extremely high. Because it is an in-memory database, all read and write operations are carried out in memory, so the read and write speed of Redis can reach 100000 ops.
Compared with other in-memory databases, ● Redis also provides rich data interfaces, such as string (strings), hash (hashes), list (lists), set (sets), ordered set (sorted sets), etc. Settings include bitmaps,hyperloglogs and geospatial (geo) operation query. This may be an important reason why most developers choose Redis over other in-memory databases.
Although ● is a memory database, it also provides persistence. Redis currently ranks seventh in DB-Engines Ranking (https://db-engines.com/en/ranking)), and almost all public cloud platforms offer Redis services. Although Redis has high performance, we should also pay attention to its runtime state when using Redis. According to this information, we can optimize the method of using Redis on the one hand, and analyze it when the application times out and responds very slowly on the other hand.
At this point, you must mention a very useful command provided by Redis to view status information: info. Connect to redis using redis-cli, enter the info all command, and redis-server will return the status information of Redis. The details are as follows:
Among them, memory,stats,clients,keyspace is the information that Redis runtime often pays attention to, which can effectively help us to focus on the information we need to know in detail in these four columns.
First, in-depth analysis of Redis's most important memory
For Redis, memory is the most important resource, so this article first introduces how to view the memory status information of Redis, that is, the memory column:
The amount of memory allocated by the ● used_memory:Redis allocator, that is, the total amount of memory actually stored.
● used_memory_human: displays the used_memory in a readable format.
● used_memory_rss: displays the total physical memory consumed by Redis processes from an operating system perspective.
● used_memory_rss_human: displaying used_memory_rss in readable format
● mem_fragmentation_ratio:used_memory_rss / used_memory ratio, which represents the memory fragmentation rate.
Used_memory reflects the current memory usage of data stored in Redis. When the memory usage reaches the maxmemory set by Redis, Redis will remove the data stored in memory in different ways according to the setting of memory data eviction policy. For example, if the policy is set to noeviction, Redis will directly return an error message.
Understanding the memory fragmentation rate represented by mem_fragmentation_ratio is very important to optimize the resource performance of Redis instances. It is reasonable that the fragmentation rate of memory is slightly greater than 1. At this time, the fragmentation rate of memory is still relatively low, which also shows that swap has not occurred in Redis. However, if the value of the memory fragmentation rate exceeds 1.5, it means that Redis consumes 150% of the actual physical memory, of which 50% is the memory fragmentation rate, which can be directly determined as Redis memory fragmentation is too large.
Is it true that the lower the memory fragmentation rate, the better? The answer is no. When the memory fragmentation rate is less than 1, the Redis memory allocation exceeds the physical memory, and the operating system is in the process of swap,Redis. Some of the data may be swapped to the hard disk. Swap can seriously affect the performance of Redis and cause great latency.
2. Stats helps you fully understand the status of Redis
Stats can count the basic information of Redis, such as the number of connections, commands, network, synchronization status and other very important information of Redis. Here are some important pieces of information:
● total_connections_received: the total number of clients connected.
● total_commands_processed: the total number of commands processed.
● instantaneous_ops_per_sec: the number of commands processed per second.
The number of ● keyspace_hits:keyspace hits.
The number of ● keyspace_misses:keyspace misses.
● rejected_connections: the number of connections rejected due to maxclients restrictions.
The total number of expired events in ● expired_keys:key.
● evicted_keys: the total number of key reclaimed due to maxmemory restrictions.
Total_connections_received
And total_commands_processed reflects the number of connections and commands that have been processed since the Redis server was started. Instantaneous_ops_per_sec reflects the busy state of the Redis server. When the value of rejected_connections is not 0, the number of connections applied is too large, or the configuration of maxclients is too small.
For applications, keyspace_hits and keyspace_misses are two key indicators. Redis sets special identity attributes for all its commands, such as "read-only", "write", or "administrative commands". In the Redis source code, take a look at the sflags member properties field in the redisCommand structure to see which properties the command has.
For example:
For example, w represents a write command (such as the set,del command), r represents a read-only command (get,hmget command), and a represents an administrative command (config,shutdown). Both keyspace_hits and keyspace_misses do statistics for Redis operation commands with read-only attributes. If the keyspace_ misses value calculated by info is too high, or if it has grown rapidly in the past period of time, it means that the data obtained from Redis has not been obtained during this period of time. At this time, it may be necessary to check the storage and access of application data in Redis.
If key is used within a specified time period, or if the old key may not be used in the future, you can use the Redis expiration time command (expire,expireat, pexpire, pexpireat, etc.) to set the expiration time, so that Redis will automatically delete the key when the key expires, which can be viewed through expired_keys.
When the memory usage reaches the maximum threshold maxmemory, Redis will eliminate the data stored in Redis according to the set key eviction policy. This information can be viewed according to evicted_keys.
Third, interpret the significance of the number of Redis connections.
Clients includes the number of connections, input and output buffering, and the number of blocked command connections.
● connected_clients: the number of client connections.
● client_longest_output_list: the longest output list in the current client connection.
● client_biggest_input_buf: the largest input buffer in the current client connection.
● blocked_clients: the number of clients waiting due to blocking calls (BLPOP, BRPOP, BRPOPLPUSH).
The number of connections can actually be regarded as a limited resource for Redis. Generally, Redis is configured with a limit on the maximum number of connections, so it is also important to understand this to ensure the normal connection of the application. If the client_longest_output_list is too high, it is likely that there is an exception in Redis, and you may need to combine clients list to troubleshoot the client connection. When the blocking command is used, blocked_clients also needs to pay attention.
4. Keyspace helps you understand the status of the data
Keyspace mainly provides statistics about the main dictionary of each Redis database. These statistics include the number of keys, the number of key with expiration time, and the average time to live. For each database, the format of each row of information displayed in the keyspace column is as follows:
DbX: keys=X,expires=X,avg_ttl=X
Where the first X represents the number of the database, the second X represents the number of keys, the third X represents the number of keys with expiration time, and the fourth X represents the average lifetime of the key. For example:
Db0:keys=6,expires=0,avg_ttl=0: this means that the total number of key in database 0 is 6, the total number of key with expiration time is 0, and the average survival time is 0.
Other information about the Redis Info command is also briefly introduced here: for example, the server column displays some information about the Redis server itself, such as version number, operating system, port, and so on. Persistence and replication are related to database persistence and master / slave replication. Cpu reflects the CPU usage information of the Redis server. Commandstas displays the details of all command execution in Redis, including the number of command calls, the total CPU time consumed by the command, and the average CPU time spent per command execution. Cluster is mainly used to reflect the characteristics of the cluster.
The above is all the contents of the article "how to use info commands in Redis". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.