Redis INFO命令

Redis INFO命令教程

Redis 的 INFO 命令用于以一种易于理解和阅读的格式,返回关于 Redis 服务器的各种信息和统计数值。通过给定可选的参数 section ,可以让命令只返回某一部分的信息。

Redis INFO命令详解

语法

192.168.98.70:6379> INFO [section]

Redis INFO Server section

字段 描述
redis_version Redis 服务器版本
redis_git_sha1 Git SHA1
redis_git_dirty Git dirty flag
os Redis 服务器的宿主操作系统
arch_bits 架构(32 或 64 位)
multiplexing_api Redis 所使用的事件处理机制
gcc_version 编译 Redis 时所使用的 GCC 版本
process_id 服务器进程的 PID
run_id Redis 服务器的随机标识符(用于 Sentinel 和集群)
tcp_port TCP/IP 监听端口
uptime_in_seconds 自 Redis 服务器启动以来,经过的秒数
uptime_in_days 自 Redis 服务器启动以来,经过的天数
lru_clock 以分钟为单位进行自增的时钟,用于 LRU 管理

Redis INFO clients section

字段 描述
connected_clients 已连接客户端的数量(不包括通过从属服务器连接的客户端)
client_longest_output_list 当前连接的客户端当中,最长的输出列表
client_longest_input_buf 当前连接的客户端当中,最大输入缓存
blocked_clients 正在等待阻塞命令(BLPOP、BRPOP、BRPOPLPUSH)的客户端的数量

Redis INFO memory section

字段 描述
used_memory 由 Redis 分配器分配的内存总量,以字节(byte)为单位
used_memory_human 以人类可读的格式返回 Redis 分配的内存总量
used_memory_rss 从操作系统的角度,返回 Redis 已分配的内存总量(俗称常驻集大小)。这个值和 top 、 ps 等命令的输出一致。
used_memory_peak Redis 的内存消耗峰值(以字节为单位)
used_memory_peak_human 以人类可读的格式返回 Redis 的内存消耗峰值
used_memory_lua Lua 引擎所使用的内存大小(以字节为单位)
mem_fragmentation_ratio used_memory_rss 和 used_memory 之间的比率
mem_allocator 在编译时指定的, Redis 所使用的内存分配器。可以是 libc 、 jemalloc 或者 tcmalloc 。

Redis INFO其他section

字段 描述
persistence RDB 和 AOF 的相关信息
stats 一般统计信息
replication 主/从复制信息
cpu CPU 计算量统计信息
commandstats Redis 命令统计信息
cluster Redis 集群信息
keyspace 数据库相关的统计信息

Redis内存相关参数说明

在理想情况下, used_memory_rss 的值应该只比 used_memory 稍微高一点儿。当 rss > used ,且两者的值相差较大时,表示存在(内部或外部的)内存碎片。

内存碎片的比率可以通过 mem_fragmentation_ratio 的值看出。当 used > rss 时,表示 Redis 的部分内存被操作系统换出到交换空间了,在这种情况下,操作可能会产生明显的延迟。

当 Redis 释放内存时,分配器可能会,也可能不会,将内存返还给操作系统。如果 Redis 释放了内存,却没有将内存返还给操作系统,那么 used_memory 的值可能和操作系统显示的 Redis 内存占用并不一致。查看 used_memory_peak 的值可以验证这种情况是否发生。

返回值

字符串,文本行的集合。

时间复杂度

O(1)

可用版本

>= 1.0.0

案例

INFO查看服务器信息

使用 INFO 命令查看服务器信息

127.0.0.1:6379> INFO # Server redis_version:5.0.5 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:2299e57d583efc7c redis_mode:standalone os:Linux 3.10.0-327.el7.x86_64 x86_64 arch_bits:64 multiplexing_api:epoll atomicvar_api:atomic-builtin gcc_version:4.8.5 process_id:9415 run_id:6ace027140a149b47f50f91bd7032becc966e0d7 tcp_port:6379 uptime_in_seconds:2909 uptime_in_days:0 hz:10 configured_hz:10 lru_clock:2187936 executable:/home/redis-server config_file: # Clients connected_clients:10 client_recent_max_input_buffer:4 client_recent_max_output_buffer:0 blocked_clients:0 # Memory used_memory:1042080 used_memory_human:1017.66K used_memory_rss:2998272 used_memory_rss_human:2.86M used_memory_peak:1042080 used_memory_peak_human:1017.66K used_memory_peak_perc:100.00% used_memory_overhead:994274 used_memory_startup:792264 used_memory_dataset:47806 used_memory_dataset_perc:19.14% allocator_allocated:1115064 allocator_active:1327104 allocator_resident:3907584 total_system_memory:8203091968 total_system_memory_human:7.64G used_memory_lua:37888 used_memory_lua_human:37.00K used_memory_scripts:0 used_memory_scripts_human:0B number_of_cached_scripts:0 maxmemory:0 maxmemory_human:0B maxmemory_policy:noeviction allocator_frag_ratio:1.19 allocator_frag_bytes:212040 allocator_rss_ratio:2.94 allocator_rss_bytes:2580480 rss_overhead_ratio:0.77 rss_overhead_bytes:-909312 mem_fragmentation_ratio:3.00 mem_fragmentation_bytes:1998192 mem_not_counted_for_evict:0 mem_replication_backlog:0 mem_clients_slaves:0 mem_clients_normal:202010 mem_aof_buffer:0 mem_allocator:jemalloc-5.1.0 active_defrag_running:0 lazyfree_pending_objects:0 # Persistence loading:0 rdb_changes_since_last_save:7 rdb_bgsave_in_progress:0 rdb_last_save_time:1579244271 rdb_last_bgsave_status:ok rdb_last_bgsave_time_sec:-1 rdb_current_bgsave_time_sec:-1 rdb_last_cow_size:0 aof_enabled:0 aof_rewrite_in_progress:0 aof_rewrite_scheduled:0 aof_last_rewrite_time_sec:-1 aof_current_rewrite_time_sec:-1 aof_last_bgrewrite_status:ok aof_last_write_status:ok aof_last_cow_size:0 # Stats total_connections_received:10 total_commands_processed:8 instantaneous_ops_per_sec:0 total_net_input_bytes:208 total_net_output_bytes:90 instantaneous_input_kbps:0.00 instantaneous_output_kbps:0.00 rejected_connections:0 sync_full:0 sync_partial_ok:0 sync_partial_err:0 expired_keys:0 expired_stale_perc:0.00 expired_time_cap_reached_count:0 evicted_keys:0 keyspace_hits:0 keyspace_misses:0 pubsub_channels:0 pubsub_patterns:0 latest_fork_usec:0 migrate_cached_sockets:0 slave_expires_tracked_keys:0 active_defrag_hits:0 active_defrag_misses:0 active_defrag_key_hits:0 active_defrag_key_misses:0 # Replication role:master connected_slaves:0 master_replid:c77fed1264cfa60e5294a8219843f69964538e1e master_replid2:0000000000000000000000000000000000000000 master_repl_offset:0 second_repl_offset:-1 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0 # CPU used_cpu_sys:0.944082 used_cpu_user:1.256416 used_cpu_sys_children:0.000000 used_cpu_user_children:0.000000 # Cluster cluster_enabled:0 # Keyspace

我们使用了 INFO 命令查看了服务器的所有的配置。

INFO查看服务器指定section信息

使用 INFO 命令查看服务器指定 section 信息

127.0.0.1:6379> INFO server # Server redis_version:5.0.5 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:2299e57d583efc7c redis_mode:standalone os:Linux 3.10.0-327.el7.x86_64 x86_64 arch_bits:64 multiplexing_api:epoll atomicvar_api:atomic-builtin gcc_version:4.8.5 process_id:9415 run_id:6ace027140a149b47f50f91bd7032becc966e0d7 tcp_port:6379 uptime_in_seconds:2947 uptime_in_days:0 hz:10 configured_hz:10 lru_clock:2187974 executable:/home/redis-server config_file:

我们使用了 INFO 后面加上了指定的 section 命令查看了服务器的指定的 section 的配置。

Redis INFO命令总结

Redis 的 INFO 命令用于以一种易于理解和阅读的格式,返回关于 Redis 服务器的各种信息和统计数值。