The Redis server is an event-driven program that mainly handles two types of events: file events and time events. The processing of these events is closely related to the execution of Redis commands. Next, I will use the Redis server command as the starting point to deeply analyze its working principle and importance.
First, we first understand what commands are available on the Redis server. As of 2021, the commands supported by Redis are:
- Key operation commands, such as
keys *
,expire key seconds
,ttl key
,del key
,exists key
, etc., used to handle keys in Redis. - Database operation commands, such as
select n
,flushdb
,flushall
, etc., are used to operate the database in Redis. - Data type commands, Redis supports multiple data types, including Strings, Lists, Sets, Hashes and Sorted Sets, etc. Each type has a corresponding command, such as
set key value
that stores specified key-value pairs. , get theget key
of the specified key-value pair, etc.
These commands are the basis for efficient data operations on the Redis server. For example, through key operation commands, the client can effectively manage and query keys in Redis; database operation commands enable Redis to support multiple databases and facilitate database addition, deletion, modification and query operations; and data type commands, Redis can store and manage complex data structures, such as lists, sets, hash tables, ordered sets, etc.
Then let’s look at the importance of Redis server commands. As a high-performance in-memory database, Redis’ commands not only provide basic operations such as adding, deleting, checking, and modifying data, but also provide rich data management functions. For example, using the ordered set ZSet, you can sort elements by score; through operations such as intersection and union, you can implement the intersection, union, and difference operations of sets; using distributed locks, you can implement different Synchronization security issues of operations on shared data between servers. In addition, Redis also supports the publish/subscribe model, which can implement functions such as message queues.
In general, Redis server commands are one of the core functions of Redis. They enable Redis to have rich data operation and management functions and can meet the needs of various complex application scenarios. At the same time, Redis’s I/O multiplexing technology allows Redis to effectively process multiple events when they occur concurrently, thus ensuring its high performance and real-time performance.
1. Function of info command
Execute the INFO command on the redis client to return all information and statistical data about the redis server in a simple format that is easy for computer parsing and human reading.
Optional parameters can be used to select specific parts of the information:
- Server server basic information
- Clients client connection information
- Memory memory information
- PersistencePersistence related
- Stats try monitoring information
- Replication master-slave replication related information
- CPU information
- Cluster cluster information
- Keyspace key stores space information
Please note that depending on the version of Redis, some fields have been added or removed. Therefore, strong clients should parse the results of this command by skipping unknown attributes and handle missing fields gracefully
#Inputting on the client will return the following information info
2. Server basic information
# redis version number redis_version:5.0.3 # redis source package git information redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:da69b07a37c06dc8 # Run mode ("standalone", "sentinel" or "cluster") redis_mode:standalone # Operating system information os:Linux 3.10.0-514.el7.x86_64 x86_64 # 64-bit architecture arch_bits:64 # Underlying dependency information for compilation and running multiplexing_api:epoll atomicvar_api:atomic-builtin gcc_version:4.8.5 # Process ID process_id:10040 # Random value identifier for instance running (useful in sentinel and cluster) run_id:df903681f11f712523e0615cd4c7e45afbf500b6 #port tcp_port:6379 # Running time uptime_in_seconds:42593 # Running time (days) uptime_in_days:0 # Server frequency settings hz:10 configured_hz:10 # LRU operation clock (in minutes) lru_clock:7473903 # executable file executable:/usr/local/redis/./bin/redis-server # Currently read configuration config_file:/usr/local/redis/conf/redis_6379.conf
3. Clients client connection information
# Number of connections connected_clients:1 # Client input buffer client_recent_max_input_buffer:2 #Client output buffer client_recent_max_output_buffer:0 # Number of blocked clients (check this if you are stuck) blocked_clients:0
4. Memory information
# Total memory (number of bytes) used_memory:854280 # Total memory (more convenient to view format) used_memory_human:834.26K #Total amount of allocated memory used_memory_rss:8388608 used_memory_rss_human:8.00M # Peak memory consumption used_memory_peak:854280 used_memory_peak_human:834.26K #Percentage of memory occupied by peak memory used_memory_peak_perc:100.15% #Memory required for internal mechanisms used_memory_overhead:840838 #Memory consumed at startup used_memory_startup:791032 #The memory size occupied by data used_memory_dataset:13442 # Percentage of memory size occupied by data used_memory_dataset_perc:21.25% # Unspecified (it can be seen from the name that it is memory application information) allocator_allocated:844856 allocator_active:1011712 allocator_resident:3665920 # Entire system memory total_system_memory:1041199104 total_system_memory_human:992.96M #Memory occupied by Lua script storage used_memory_lua:37888 used_memory_lua_human:37.00K # unspecified used_memory_scripts:0 used_memory_scripts_human:0B number_of_cached_scripts:0 #Maximum memory configuration maxmemory:0 maxmemory_human:0B # Memory management strategy maxmemory_policy:noeviction # No official explanation allocator_frag_ratio:1.20 allocator_frag_bytes:166856 allocator_rss_ratio:3.62 allocator_rss_bytes:2654208 rss_overhead_ratio:2.29 rss_overhead_bytes:4722688 mem_fragmentation_ratio:10.33 mem_fragmentation_bytes:7576576 mem_not_counted_for_evict:0 mem_replication_backlog:0 mem_clients_slaves:0 mem_clients_normal:49694 mem_aof_buffer:0 # Memory allocator, selected at compile time mem_allocator:jemalloc-5.1.0 # Whether defragmentation is active active_defrag_running:0 # Number of objects waiting to be released lazyfree_pending_objects:0
5. Persistence related
# Flag indicating whether Redis is loading backup files loading:0 # The number of RDB modifications since the last dump rdb_changes_since_last_save:2 # Flag indicating that Redis is saving RDB rdb_bgsave_in_progress:0 # The timestamp of the last successful RDB save rdb_last_save_time:1550935182 # The status of the last RDB save operation rdb_last_bgsave_status:ok # Duration of the last RDB save operation (in seconds) rdb_last_bgsave_time_sec:-1 # The duration of the ongoing RDB save operation (if any) rdb_current_bgsave_time_sec:-1 # Size of bytes allocated by copy-on-write during the last RBD save operation rdb_last_cow_size:0 # Indicates that the flag of AOF recording is activated aof_enabled:1 # Flag indicating that the AOF rewrite operation is in progress aof_rewrite_in_progress:0 # Once the ongoing RDB save is completed, the flag indicating the AOF rewrite operation will be specified. aof_rewrite_scheduled:0 #The duration of the last AOF rewrite operation, in seconds aof_last_rewrite_time_sec:-1 # The duration of the ongoing AOF rewrite operation (if any) aof_current_rewrite_time_sec:-1 #The status of the last AOF rewrite operation aof_last_bgrewrite_status:ok #The status of the last write operation to AOF aof_last_write_status:ok # Size (in bytes) of the copy-on-write allocation during the last AOF rewrite operation aof_last_cow_size:0 # AOF current file size aof_current_size:77 # AOF file size at latest startup or rewrite aof_base_size:77 # Once the ongoing RDB save is completed, the flag indicating the AOF rewrite operation will be specified. aof_pending_rewrite:0 #The size of the AOF buffer aof_buffer_length:0 #The size of the AOF rewrite buffer aof_rewrite_buffer_length:0 # Number of fsync pending jobs aof_pending_bio_fsync:0 # Delay fsync counter aof_delayed_fsync:0 # If there may be these values in data recovery # loading_start_time: timestamp when loading operation starts # loading_total_bytes: total file size # loading_loaded_bytes: Number of bytes loaded # loading_loaded_perc: The same value expressed as a percentage # loading_eta_seconds: How many seconds ETA completes loading
6. Stats try monitoring information
# Total number of connections accepted by the Redis server total_connections_received:1 #The total number of commands processed by the Redis server total_commands_processed:1 #Number of commands processed per second instantaneous_ops_per_sec:0 #The total amount of data received over the network, in bytes total_net_input_bytes:34 #The total amount of data sent over the network, in bytes total_net_output_bytes:7 # The rate at which data is received per second, in kbps instantaneous_input_kbps:0.00 # The rate at which data is sent per second, in kbps instantaneous_output_kbps:0.00 #The number of connections rejected by the Redis server due to maxclients limit rejected_connections:0 #The number of complete synchronizations between the Redis master and the slave sync_full:0 #The number of times the Redis server accepts PSYNC requests sync_partial_ok:0 #The number of times the Redis server rejects PSYNC requests sync_partial_err:0 #Total number of key expiration events expired_keys:0 expired_stale_perc:0.00 expired_time_cap_reached_count:0 # The total number of keys that have been reclaimed due to maxmemory limitations evicted_keys:0 # The number of times the key was successfully found in the main dictionary keyspace_hits:1 # The number of times the key was unsuccessfully found in the main dictionary keyspace_misses:0 #Total number of publish/subscribe channels pubsub_channels:0 # The total number of publish/subscribe modes that the client subscribes to pubsub_patterns:0 # The time consumed by the latest fork operation, in microseconds latest_fork_usec:0 # Migrate the number of cached sockets migrate_cached_sockets:0 # Number of keys tracked for key expiration (only applicable to writable replicas) slave_expires_tracked_keys:0 # The number of value reallocations performed by the defragmentation process active_defrag_hits:0 # Number of abort value reallocations initiated by the defragmentation process active_defrag_misses:0 # Number of keys for defragmentation active_defrag_key_hits:0 # Number of keys skipped during defragmentation active_defrag_key_misses:0
7. Replication master-slave replication related information
# Role master or slave role:master #The number of connected Redis slaves connected_slaves:0 # The master's identification id during the master-slave replication process master_replid:6ea01bd968c7f14cb6de138462ddaf11930a4269 master_replid2:0000000000000000000000000000000000000000 # Global copy offset master_repl_offset:0 second_repl_offset:-1 # Indicates whether the Redis server enables replication backup logs for partial synchronization repl_backlog_active:0 # The size of the backup log circular buffer repl_backlog_size:1048576 # Copy offset of the first byte in the backup log buffer repl_backlog_first_byte_offset:0 # Actual data length of backup log repl_backlog_histlen:0 # Some additional information that may be available in the case of master-slave replication # master_host: the host name or IP address of the Redis host # master_port: TCP port that the Redis host listens to # master_link_status: link status (connected/disconnected # master_last_io_seconds_ago: The elapsed time since the last interaction with the Redis host, in seconds # master_sync_in_progress: Indicates that the Redis host is synchronizing data to the slave machine # master_sync_left_bytes: The total amount of data remaining before synchronization is completed, in bytes # master_sync_last_io_seconds_ago: During a SYNC operation, the elapsed time since the last I/O operation to transmit data, in seconds. # master_link_down_since_seconds: The time since the link was disconnected, in seconds
8. CPU information
# System CPU consumed by the server used_cpu_sys:26.932586 # User CPU consumed by the server used_cpu_user:36.964424 # System CPU consumed by background processes used_cpu_sys_children:0.000000 # User CPU consumed by background processes used_cpu_user_children:0.000000
9. Cluster information
# A flag value to record whether the cluster function has been enabled cluster_enabled:0
10. Keyspace key storage space information
# The number of keys in the database, the number of keys within the validity period, and the number of expired keys db0:keys=2,expires=0,avg_ttl=0