深入理解Redis查看内存数据(redis查看内存数据)

Redis是一种内存数据库,其以缓存、持久化和发布/订阅等方式作为其主要用途。因此,深入理解Redis,能够更好的利用这种数据库,并发挥其最大的优势。

本文将介绍Redis如何查看内存数据。

在Redis中,可以使用以下命令来查看内存数据:

1. info

这个命令将返回Redis的统计信息,包括服务器的习惯,日志,客户端,内存,网络和持久化等。其中,”used_memory”表示Redis使用的内存量。

127.0.0.1:6379> info
# Server
redis_version:5.0.5
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:"57635971be685966"
redis_mode:standalone
os:Windows
arch_bits:64
multiplexing_api:winsock_IOCP
atomicvar_api:atomic-builtin
gcc_version:0.0.0
process_id:20760
run_id:cfcf7259218f7b598d83b9c9e6e1a6b8d6b0e377
tcp_port:6379
uptime_in_seconds:155
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:2410625
executable:
config_file:

# Clients
connected_clients:1
client_recent_max_input_buffer:2
client_recent_max_output_buffer:0
blocked_clients:0

# Memory
used_memory:907816
used_memory_human:886.57K
used_memory_rss:2450944
used_memory_rss_human:2.34M
used_memory_peak:917512
used_memory_peak_human:896.07K
used_memory_peak_perc:98.90%
used_memory_overhead:883622
used_memory_startup:791384
used_memory_dataset:242194
used_memory_dataset_perc:50.15%
allocator_allocated:992288
allocator_active:1351680
allocator_resident:2542592
total_system_memory:17055730688
total_system_memory_human:15.90G
used_memory_lua:36864
used_memory_lua_human:36.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.36
allocator_frag_bytes:358392
allocator_rss_ratio:1.88
allocator_rss_bytes:1190912
rss_overhead_ratio:0.96
rss_overhead_bytes:-859648
mem_fragmentation_ratio:2.70
mem_fragmentation_bytes:1543128
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:14684
mem_aof_buffer:0
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1587960188
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:2
total_commands_processed:3
instantaneous_ops_per_sec:0
total_net_input_bytes:56
total_net_output_bytes:1754
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:1
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:4099
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
tracking_total_keys:0
tracking_total_items:0
tracking_total_prefixes:0
unexpected_error_replies:0
total_reads_processed:0
total_writes_processed:0
io_threaded_reads_processed:0
io_threaded_writes_processed:0

# Replication
role:master
connected_slaves:0
master_replid:99a16810e2ba8319aad42c34d7a8cfeb04f2ceb1
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.031247
used_cpu_user:0.000000
used_cpu_sys_children:0.000000
used_cpu_user_children:0.000000

# Cluster
cluster_enabled:0
# Keyspace

2. monitor

这个命令将打开一个Redis重定向套接字,并产生所有服务器接收和发送的Redis协议输出,即所有发送和接收的命令序列,以及所有的结果。这是一种调试策略,特别是在调试Redis慢查询的时候。

127.0.0.1:6379> monitor
OK
1587821452.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实例的响应速度,以及有效抑制慢查询。


数据运维技术 » 深入理解Redis查看内存数据(redis查看内存数据)