深入理解Redis查看内存数据(redis查看内存数据)
Redis是一种内存数据库,其以缓存、持久化和发布/订阅等方式作为其主要用途。因此,深入理解Redis,能够更好的利用这种数据库,并发挥其最大的优势。
本文将介绍Redis如何查看内存数据。
在Redis中,可以使用以下命令来查看内存数据:
1. info
这个命令将返回Redis的统计信息,包括服务器的习惯,日志,客户端,内存,网络和持久化等。其中,”used_memory”表示Redis使用的内存量。
127.0.0.1:6379> info
# Serverredis_version:5.0.5
redis_git_sha1:00000000redis_git_dirty:0
redis_build_id:"57635971be685966"redis_mode:standalone
os:Windowsarch_bits:64
multiplexing_api:winsock_IOCPatomicvar_api:atomic-builtin
gcc_version:0.0.0process_id:20760
run_id:cfcf7259218f7b598d83b9c9e6e1a6b8d6b0e377tcp_port:6379
uptime_in_seconds:155uptime_in_days:0
hz:10configured_hz:10
lru_clock:2410625executable:
config_file:
# Clientsconnected_clients:1
client_recent_max_input_buffer:2client_recent_max_output_buffer:0
blocked_clients:0
# Memoryused_memory:907816
used_memory_human:886.57Kused_memory_rss:2450944
used_memory_rss_human:2.34Mused_memory_peak:917512
used_memory_peak_human:896.07Kused_memory_peak_perc:98.90%
used_memory_overhead:883622used_memory_startup:791384
used_memory_dataset:242194used_memory_dataset_perc:50.15%
allocator_allocated:992288allocator_active:1351680
allocator_resident:2542592total_system_memory:17055730688
total_system_memory_human:15.90Gused_memory_lua:36864
used_memory_lua_human:36.00Kused_memory_scripts:0
used_memory_scripts_human:0Bnumber_of_cached_scripts:0
maxmemory:0maxmemory_human:0B
maxmemory_policy:noevictionallocator_frag_ratio:1.36
allocator_frag_bytes:358392allocator_rss_ratio:1.88
allocator_rss_bytes:1190912rss_overhead_ratio:0.96
rss_overhead_bytes:-859648mem_fragmentation_ratio:2.70
mem_fragmentation_bytes:1543128mem_not_counted_for_evict:0
mem_replication_backlog:0mem_clients_slaves:0
mem_clients_normal:14684mem_aof_buffer:0
mem_allocator:libcactive_defrag_running:0
lazyfree_pending_objects:0
# Persistenceloading:0
rdb_changes_since_last_save:0rdb_bgsave_in_progress:0
rdb_last_save_time:1587960188rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0aof_enabled:0
aof_rewrite_in_progress:0aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:okaof_last_write_status:ok
aof_last_cow_size:0
# Statstotal_connections_received:2
total_commands_processed:3instantaneous_ops_per_sec:0
total_net_input_bytes:56total_net_output_bytes:1754
instantaneous_input_kbps:0.00instantaneous_output_kbps:0.00
rejected_connections:0sync_full:0
sync_partial_ok:0sync_partial_err:0
expired_keys:0expired_stale_perc:0.00
expired_time_cap_reached_count:0evicted_keys:0
keyspace_hits:1keyspace_misses:0
pubsub_channels:0pubsub_patterns:0
latest_fork_usec:4099migrate_cached_sockets:0
slave_expires_tracked_keys:0active_defrag_hits:0
active_defrag_misses:0active_defrag_key_hits:0
active_defrag_key_misses:0tracking_total_keys:0
tracking_total_items:0tracking_total_prefixes:0
unexpected_error_replies:0total_reads_processed:0
total_writes_processed:0io_threaded_reads_processed:0
io_threaded_writes_processed:0
# Replicationrole:master
connected_slaves:0master_replid:99a16810e2ba8319aad42c34d7a8cfeb04f2ceb1
master_replid2:0000000000000000000000000000000000000000master_repl_offset:0
second_repl_offset:-1repl_backlog_active:0
repl_backlog_size:1048576repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
# CPUused_cpu_sys:0.031247
used_cpu_user:0.000000used_cpu_sys_children:0.000000
used_cpu_user_children:0.000000
# Clustercluster_enabled:0
# Keyspace
2. monitor
这个命令将打开一个Redis重定向套接字,并产生所有服务器接收和发送的Redis协议输出,即所有发送和接收的命令序列,以及所有的结果。这是一种调试策略,特别是在调试Redis慢查询的时候。
127.0.0.1:6379> monitor
OK1587821452.199326 [0 127.0.0.1:35828] "info"
1587821456.270901 [0 127.0.0.1:35828] "get" "name"
3. client list
这个命令将返回当前与Redis服务器连接的所有客户端的详细信息,包括客户端ID,IP地址,端口号,连接状态,请求信息和最近的执行命令等。
127.0.0.1:6379> client list
id=1 addr=127.0.0.1:35828 fd=6 name= age=16182 idle=16182 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=monitor
4. slowlog get
这个命令将返回慢查询日志。慢查询指超过配置时间阈值的命令执行,将实现对Redis实例性能的追踪和监视。
127.0.0.1:6379> slowlog get
1) 1) (integer) 8 2) (integer) 1547810016
3) (integer) 14721 4) 1) "set"
2) "name" 3) "Redis"
5) (integer) 145 6) (integer) 1
2) 1) (integer) 5 2) (integer) 1547809918
3) (integer) 20530 4) 1) "get"
2) "name" 5) (integer) 76
6) (integer) 1
掌握Redis中的这些命令可以帮助您更好地查看和分析内存数据,加快Redis实例的响应速度,以及有效抑制慢查询。