Hello, I am Amu, a happy pirate.

Today, let’s introduce the info command to view the detailed information of redis!

A few years ago, when I was interviewing for an internship in zhengzhou, my hometown (I hadn’t graduated at that time), THE interviewer asked me a question. The interviewer came from Baidu headquarters as an engineer with 6 years of Java development experience and more than 3 years of PHP development experience. I was basically the younger brother in front of him. Although I barely passed the entrance, I was ridiculed mercilessly by the operation and maintenance. In a fit of anger, I that night on the evil fill a wave…… I still remember it till now

However, to be honest, at that time, I really did not have a detailed look at the parameter information of Redis; Have you read the parameter configuration on the Redis website?

Ha-ha, don’t be so modest. I guess the developers who just graduated or interned, or even graduated one or two years ago, didn’t really read it (I was one of them, I only used it on a basic basis). Suddenly think will use and know are two different things;

Often can hear other colleagues or network messages, will use the line, know so much why. CTRL + C and CTRL + V This is the highest level of programmer coding. Is that what everyone thinks? 😂 😂 😂

There is a saying called: know its principle, can be changed “I gibber, not really”. So today we clearly understand the internal running parameters of Redis through the INFO directive.

01) Detailed module

It can be clearly seen from the figure above that we divide the parameters of Redis into 9 modules, and each module corresponds to:

  • Server module: mainly refers to the Redis serverEnvironmental parameters; For example, system version number, server version number, and so on.
  • Clients module: Mainly refers toClient information; For example: number of client connections, number of blocking waits, buffer values, and so on.
  • Memory module: Mainly refers to the serverMemory consumption information; For example, memory usage and redis peak data.
  • Persistence module: RedispersistenceInformation; For example, whether the last RDB persistence was successful, whether the server is loading persistence files, and so on.
  • Stats module: Mainly refers toUsed for statistics of general data; For example, 1/s concurrent number, 1/min data amount, hit number, and so on.
  • Replication module: Mainly refers toThe primary/secondary synchronization information is synchronizedInstructions; Number of synchronization successes and synchronization failures.
  • Cpu module: Mainly refers toCPU Statistics; For example, the summation of CPU usage for core state/user state, etc.
  • Cluster module: Mainly refers toCluster information; For example, whether to enable cluster mode and so on.
  • KeySpace module: Mainly refers toCount the number of key pairs. For example, the number of successful lookup keys, the number of failed lookup keys, and so on.

02) Why?

If you’re already a god, you don’t need to know. However, those who are just entering the workplace or working for one, two, or even three years may not necessarily know this knowledge.

Now most companies have configured professional operation and maintenance, DBA, environment building, Redis cluster, master and slave architecture are all done by them, don’t we need to learn development?

In the interview, many developers have answered like this: “The company has a professional operation and maintenance team, many of which we can not participate in, so there is no actual field. Only business needs development “. In this way, it is obvious that our technical iteration cannot go ahead. A development will not only do business requirements, but more importantly, understand the accumulation of knowledge: mysql master, master and slave; Redis multi-master and multi-slave deployment; Docker, K8S, etc., even if they are not deployed by us, we also need to know how it is, how the company’s architecture is, how it is implemented, and how the process specification is?

That’s why it’s important to know, even though it seems like a very basic and simple article. It is estimated that many people will spray, but amu’s target group is scholars who need to consolidate and strengthen redis knowledge.

03) Detailed internal information

➜  ~ redis-cli -h localhost
localhost:6379> info

# ServerRedis_version :5.0.9 -- Redis server version redis_git_SHA1:00000000 -- Git SHA1 redis_git_dirty:0 -- Git dirty identifier Redis_build_id: 544EC503BCbee8b6 -- Internal version redis_mode:standalone -- Run mode Stand-alone or cluster OS :Darwin 17.7.0x86_64 -- Host operating system for the server 74ac11239 arch_bits:64 -- architecture (32-bit or 64-bit) multiplexing_api:kqueue -- event loop used by Redis atomicvar_api:atomic -- builtin -- atomic processing API Gcc_version: 2 - used to compile the GCC compiler version of Redis server process_id no. : 411 - business process of PID run_id: e8bf4443cdd6696036e07c4a65d64e6916a6a79e Tcp_port :6379 -- TCP/IP listening port uptime_in_seconds:29924 -- Redis server startup time in seconds Uptime_in_days :0 -- Redis server startup time (in days) Hz :10 -- Redis internal scheduling frequency (closing timeout clients, deleting expired keys, etc.) Configured_hz :10 -- The configured frequency of the server lRU_clock :9421068 -- the incremented clock for the LRU tube; The clock 100 ms (hz = 10, so every 1000 ms / 10 = 100 ms performs a crontab) updated once the executable: / usr/local/opt/redis/bin/redis - server, the server executable file paths Config_file: / usr/local/etc/redis. Conf -- the path of the redis configuration file
# ClientsConnected_clients :1 -- Number of clients that have connected (excluding clients that have connected through slave servers) client_RECent_MAX_input_buffer :2 -- Maximum recent input buffer size of the current client Client_recent_max_output_buffer :0 -- Blocked_clients :0 -- Number of clients that are waiting for blocking commands (BLPOP, BRPOP, BRPOPLPUSH)
# MemoryUsed_memory :148180600 -- The amount of memory allocated by the Redis allocator in bytes used_memory_human:1015.52K -- Returns the amount of memory allocated by Redis in a human-readable format, Used_memory_rss :3293184 - returns the total amount of memory Redis has allocated from the operating system's point of view. Used_memory_rss_human: 3.14m -- returns the total amount of memory Redis has allocated (commonly known as resident set size) in human-readable format; Used_memory_peak :1040976 -- The peak memory consumption of Redis in bytes, Used_memory_peak_human :1016.58K -- return the peak memory consumption of Redis in human-readable format used_MEMORY_peak_perc :99.90% -- (used_memory/used_memory_peak) *100%, peak memory usage usED_memory_overhead :1037198 -- The memory overhead required by Redis to maintain the internal mechanism of the dataset, Backlog used_memory_startup:987504 -- The initial amount of memory (in bytes) Redis consumes at startup Used_memory_dataset :2690 -- Bytes size of the dataset USED_memory -- USED_MEMORY_overhead USED_MEMORy_DATASet_perc :5.14% -- % of net memory usage (USed_MEMORy_dataset /(used_memory - USed_memory_startup))*100% TOTAL_system_memory :8589934592 -- the entire system memory Total_system_memory_human :16.00 GB: indicates the system memory size in units. Used_memory_lua :37888: indicates the memory used by Lua scripts Used_memory_lua_human: 37.00k -- Indicates the memory used by Lua scripts in a format understandable to normal people. Used_memory_scripts :0 -- Indicates the number of bytes used by cached Lua scripts Used_memory_scripts_human :0B -- Indicates the number of bytes used by cached Lua scripts in a format understandable to normal people. Maxmemory :0 -- Indicates the maximum number of bytes used by Redis instances. Maxmemory_human :0B -- indicates the maximum number of bytes used by Redis instances Maxmemory_policy :noeviction -- allocator_FRAG_ratio :3.24 when maxMemory is reached Allocator_frag_bytes: 2249712 allocator_rss_ratio: 1.00 allocator_rss_bytes: 0 rss_overhead_ratio: 1.01 Rss_overhead_bytes: 37888 mem_fragmentation_ratio: 3.27 mem_fragmentation_bytes: 2287600 mem_not_counted_for_evict: 0 Mem_replication_backlog :0 mem_clients_slaves mem_clients_normal:49694 mem_Aof_buffer :0 mem_allocator: LIBC -- memory allocator Active_defrag_running :0 -- indicates that no active defrag task is running, Lazyfree_pending_objects :0 -- 0 indicates that there is no delayed release of pending objects (there are also data translation tasks that are not lazy deleted)
# PersistenceRdb_changes_since_last_save :5 -- Number of commands written to last RDB file generated successfully Rdb_bgsave_in_progress :0 -- whether the server is creating the RDB file rdb_last_save_time:1620033801 -- the last time RDB was successfully saved with anumer-based timestamp seconds Rdb_last_bgsave_status: OK -- whether the last RDB persistence is successful rdb_last_bgsave_time_sec:-1 -- Time spent in the last RDB file generation successfully (in seconds) Rdb_current_bgsave_time_sec :-1 -- Duration of the ongoing RDB save operation in seconds rdb_last_cow_size:0 -- Size of the memory copied during writes during the last RDB save operation in bytes Aof_enabled :0 -- Whether aof aof_rewrite_in_progress:0 -- Indicates whether the rewrite operation on Aof is in progress. Aof_rewrite_scheduled :0 -- If the RDB is saved, run rewrite aof_last_rewrite_time_sec:-1 -- time spent in the last Aof rewrite (in seconds). Aof_current_rewrite_time_sec :-1 -- If the rewrite operation is in progress, Aof_last_bgrewrite_status: OK -- state of the last bGREWriteAof operation. Aof_last_write_status: OK -- State of the last AOF write Aof_last_cow_size :0 -- Size in bytes of memory copied during the last Aof rewrite
# StatsTotal_connections_received :1 -- Total number of connections accepted by the server (overly creating and destroying connections affects performance) Total_commands_Processed :3 -- Total number of commands processed by Redis Instantaneous_ops_per_sec :0 -- Number of commands processed per second QPS total_net_input_bytes:63 -- Total bytes of read traffic on the Redis network total_net_output_bytes:14765 -- Total bytes of write traffic on the Redis network Instantaneous_input_kbps: 0.00 - redis web portal KPS, instantaneous_output_kbps measured in KB/s: 0.00 - export KPS redis network, Rejected_connections :0 -- The number of redis connections reached the maxClients limit. Number of new connections rejected sync_FULL :0 -- Number of successful primary/secondary synchronization sync_PARTIal_OK :0 -- Number of successful primary/secondary synchronization sync_partial_ERR :0 -- Number of failed primary/secondary synchronization expired_keys:0 -- Expired_stale_perc :0.00 -- Key expiration rate expired_time_CAP_REached_count :0 -- Key expiration times evicted_keys:0 -- Keyspace_hits :0 -- Number of key misses -- number of key misses Pubsub_patterns :0 -- the number of channels currently in use by Redis. Latest_fork_usec :0 -- The number of channels currently in use How long did the last fork operation block the Redis process? In microseconds migrate_cached_sockets:0 -- Whether connections to this address have been cached. Slave_expires_tracked_keys :0 -- Number of redis keys due from the instance active_defrag_hits:0 -- Active_defrag_misses :0 -- Number of active defragmentation misses by Redis active_defrag_KEY_hits :0 -- Number of active defragmentation key hits by Redis Active_defrag_key_misses :0 -- Number of times Redis misses the defragmentation key actively
# ReplicationRole :master -- role of the Redis instance, Is the master or slave connected_slaves: 0 - connection from the slave master_replid instance number: 1 e913ad6101de7d40fcea32378f515e62a55c9db -- Master instance startup random string master_replid2:0000000000000000000000000000000000000000 - the master instance startup random string 2, supporting role, For synchronization after failover master_REPL_offset :0 -- current redis master-slave offset second_REPL_offset :-1 -- Current Redis master-slave offset 2 repl_backlog_active:0 -- Repl_backlog_size :1048576 -- Replication backlog buffer size repl_BACKlog_FIRST_BYTE_OFFSET :0 -- Size of the offset in the replication buffer Repl_backlog_histlen :0 -- The size (in bytes) of the data in the replication backlog buffer, equal to master_REPL_offset - REPL_backlog_first_BYte_offset
# CPUUsed_cpu_sys :3.629912 -- The total number of system CPUS consumed by the Redis server. This is the total number of system CPUS consumed by all server processes (main and background threads). This is the total number of user cpus consumed by all threads of the server process (main thread and background thread) Total number of user cpus consumed by background processes
# ClusterCluster_enabled :0: Specifies whether the cluster mode is enabled for the instance
# KeyspaceDb0: keys = 749916 -- Number of db0 keys Expires = 8 -- Number of keys with lifetime avg_ttl = 138855028143523 -- Average lifetimeCopy the code

Sorting here is really tired amu, too many parameters, the above is to sort out some basic parameters. But when you actually sort through the data, you realize that you thought you knew a lot; But there is more.

04) Parameters to focus on

Check the redis memory usage:

Reason: Although most large companies have kanban board which can directly see the use of Redis cluster, sometimes we need to check on the computer to determine whether there is really an exception.

➜ ~ redis - cli -h localhost info memory | grep - E '2 | human' used_memory: 1038896 used_memory_human: 1014.55 K Used_memory_rss: 1490944 used_memory_rss_human: 1.42 M used_memory_peak: 1040976 used_memory_peak_human: 1016.58 K Used_memory_peak_perc: 99.80% used_memory_lua: 37888 used_memory_lua_human: 37.00 K used_memory_scripts: 0 used_memory_scripts_human:0BCopy the code

As you can see clearly above, reDI currently allocates the total amount of memory from the operating system, as well as the memory usage (due to the high output, I deleted some data needed for the presentation).

1. Used_memory: Specifies the amount of memory (in bytes) allocated by the Redis allocator. It also includes virtual memory swap.

2. Used_memory_rss: Specifies the amount of memory (in bytes) used by the Redis process. This includes the running memory of the process itself and memory fragments.

The difference between the two is: used_memory gets the object redis; Used_memory_rss Gets the object that is the operating system; From the above results, we can see that the former is significantly smaller than the latter, because redis itself requires memory and memory fragmentation, so it looks like the former is much smaller than the latter. This does not mean that the former is necessarily less than the latter, but it is possible that the former may have virtual memory that causes the former to be larger than the latter.

Check the number of client connections:

Let’s enumerate the client parameters:

➜  ~ redis-cli -h localhost info clients
# Clients
connected_clients:1
client_recent_max_input_buffer:4
client_recent_max_output_buffer:0
blocked_clients:0
Copy the code

To view the maximum number of client connections on this host:

localhost:6379> config get maxclients
1) "maxclients"
2) "10000"
Copy the code

The reason for this comparison is that the number of connections to a client is limited by maxClients. These two parameters are important for troubleshooting problems. We may encounter redis service is not available while writing code, so first make sure redis is not down.

Telnet 127.0.0.1(redis IP address online) 80(port)Copy the code

By checking the number of links to find the abnormal state, we can use the client list command to check the client connection:

Localhost :6379> Client list ID =10 addr=127.0.0.1:56336 fd=8 Name = age=780 idle=1 flags=N db=0 sub=0 psub=0 multi=-1 Qbuf =26 qbuf-free=32742 OBL =0 OLL =0 OMem =0 events=r CMD =client The meanings of the result set returned by the copop command are as follows: ID: serial number Addr: address and port of the client fd: The file descriptor used by the socket name: connection name Age: connection duration in seconds idle: idle duration in seconds Flags: client flag db: ID of the database the client is using sub: number of subscribed channels psub: Number of subscribed modes Multi: Number of commands executed in a transaction Qbuf: Length of the query buffer (in bytes, 0 indicates that no query buffer is allocated) qbuf-free: length of the query buffer (in bytes, 0 indicates that no query buffer is allocated) obl: Length of the output buffer (in bytes, 0 indicates that no output buffer is allocated) OLl: Number of objects contained in the output list (when there is no space left in the output buffer, command replies will be queued as string objects) omem: Total memory occupied by output buffers and output lists Events: file descriptor events CMD: last command executedCopy the code

We can also check the number of connections rejected by clients to ensure that the service needs to be reconfigured:

➜ ~ redis - cli -h localhost info stats | grep reject rejected_connections: 0 - the client rejected the number of connectionsCopy the code

If this value is what we ideally expect, we need to adjust our maximum number of connections:

(1) through the redis configuration file to modify the maximum number of connections: vim/usr/local/etc/redis. Conf maxclients = 150000 (2) the redis service startup specifies the maximum number of connections:  redis-server --maxclients 150000Copy the code

There are also parameters to query for CPU information, cluster information, and master-slave replication information, so I’ll slowly put those in the next chapter and go through them with practical projects.

For now, we just need to understand some of the parameters that are commonly concerned; To tell you the truth, I don’t necessarily remember how much, but I am more familiar with the data indicators that I often see.

The final summary

Can see the friends here, your eyesight is really powerful, too many parameters need to go to look and remember, really not easy! Trouble friends to their own thumbs up, thief stick.

Although the article is relatively short, the masters may see it will scold “garbage, what is written”; Again, we’re targeting different groups. And these are not random articles written out of thin air, but after the interview of the big factory, the leader’s inquiry will be combined with their own actual situation to write out.

Do you have any further understanding of the internal parameters of Redis Info? If Amu’s article was helpful or lacking, please leave a comment below.

Finally, you are welcome to follow my personal public account “I am Amu”, which will update the back-end knowledge and study notes from time to time. Also welcome direct public account private message or email contact me, we can study together, progress together.

All right, I’m Amu, a worker who doesn’t want to be eliminated at 30 ⛽️ ⛽️ ⛽. Thanks for collecting, liking, sharing and commenting. See you next time.