gpt4 book ai didi

spring - Redis缓存内存状态

转载 作者:IT王子 更新时间:2023-10-29 06:04:15 25 4
gpt4 key购买 nike

我需要创建一个页面,我可以在其中显示 Redis 缓存内存状态,例如分配了多少内存以及使用了多少内存。有什么方法可以使用 spring boot 获取所有这些信息吗?

最佳答案

是的,这是可能的。我告诉你如何使用 Redis-client: Jedis 来做到这一点

添加后jedis依赖到您的项目中,您可以定义一个 bean,例如:

    @Bean
public JedisConnectionFactory connectionFactory() {
return new JedisConnectionFactory();
//in-case if you have a cluster
//return new JedisConnectionFactory(new RedisClusterConfiguration(Arrays.asList("127.0.0.1:6379,127.0.0.1:6369".split(","))));
}

现在您可以像这样使用它:

class DummyClass{
@Autowired
JedisConnectionFactory factory;

void printServerInfo(){
Properties info = factory.getConnection().info()
System.out.println(info)
}
}

这是一个非常基本的示例,说明如何在 spring-boot 中使用 jedis 获取服务器信息。这是一个示例输出,包含的信息:希望能满足您关于服务器的所有信息。

[  
uptime_in_seconds:6,
maxmemory_human:0 B,
aof_last_cow_size:0,
master_replid2:0000000000000000000000000000000000000000,
mem_replication_backlog:0,
aof_rewrite_scheduled:0,
total_net_input_bytes:14,
rss_overhead_ratio:1.36,
hz:10,
redis_build_id:5e26944 cbfa127d5,
aof_last_bgrewrite_status:ok,
multiplexing_api:epoll,
client_recent_max_output_buffer:0,
allocator_resident:3657728,
mem_fragmentation_bytes:4156584,
repl_backlog_first_byte_offset:0,
redis_mode:standalone,
redis_git_dirty:1,
allocator_rss_bytes:2510848,
repl_backlog_histlen:0,
rss_overhead_bytes:1310720,
total_system_memory:16679944192,
loading:0,
evicted_keys:0,
cluster_enabled:0,
redis_version:5.0 .3,
repl_backlog_active:0,
mem_aof_buffer:0,
allocator_frag_bytes:160352,
instantaneous_ops_per_sec:0,
used_memory_human:834.11 K,
role:master,
maxmemory:0,
used_memory_lua:37888,
rdb_current_bgsave_time_sec:-1,
used_memory_startup:790976,
lazyfree_pending_objects:0,
used_memory_dataset_perc:21.31 %,
allocator_frag_ratio:1.16,
arch_bits:64,
mem_clients_normal:49694,
expired_time_cap_reached_count:0,
mem_fragmentation_ratio:6.12,
aof_last_rewrite_time_sec:-1,
master_replid:95 dcc7b8b38c04621f8cbc089ce6e13c82d3ca58,
aof_rewrite_in_progress:0,
config_file:,
lru_clock:1356079,
maxmemory_policy:noeviction,
run_id:8 bfe7f1cebd97ff0dfb98436e76084db6c781010,
latest_fork_usec:0,
total_commands_processed:0,
expired_keys:0,
used_memory:854128,
mem_clients_slaves:0,
keyspace_misses:0,
executable:/redis-server,
used_memory_peak_human:834.11 K,
keyspace_hits:0,
rdb_last_cow_size:0,
used_memory_overhead:840670,
active_defrag_hits:0,
tcp_port:6379,
uptime_in_days:0,
used_memory_peak_perc:105.21 %,
blocked_clients:0,
sync_partial_err:0,
used_memory_scripts_human:0 B,
aof_current_rewrite_time_sec:-1,
aof_enabled:0,
master_repl_offset:0,
used_memory_dataset:13458,
used_cpu_user:0.011536,
rdb_last_bgsave_status:ok,
atomicvar_api:atomic-builtin,
allocator_rss_ratio:3.19,
client_recent_max_input_buffer:4,
aof_last_write_status:ok,
mem_allocator:jemalloc-5.1.0,
used_memory_scripts:0,
used_memory_peak:854128,
process_id:9682,
used_cpu_sys:0.007885,
repl_backlog_size:1048576,
connected_slaves:0,
gcc_version:7.3 .0,
total_system_memory_human:15.53 G,
sync_full:0,
connected_clients:1,
allocator_active:1146880,
total_net_output_bytes:0,
pubsub_channels:0,
active_defrag_key_hits:0,
rdb_changes_since_last_save:0,
instantaneous_input_kbps:0.00,
configured_hz:10,
used_memory_rss_human:4.74 M,
expired_stale_perc:0.00,
active_defrag_misses:0,
used_cpu_sys_children:0.000000,
number_of_cached_scripts:0,
sync_partial_ok:0,
used_memory_lua_human:37.00 K,
rdb_last_save_time:1561637161,
pubsub_patterns:0,
slave_expires_tracked_keys:0,
redis_git_sha1:9101 cbde,
used_memory_rss:4968448,
rdb_last_bgsave_time_sec:-1,
os:Linux 4.15.0-52-generic x86_64,
mem_not_counted_for_evict:0,
active_defrag_running:0,
rejected_connections:0,
active_defrag_key_misses:0,
allocator_allocated:986528,
instantaneous_output_kbps:0.00,
second_repl_offset:-1,
rdb_bgsave_in_progress:0,
used_cpu_user_children:0.000000,
total_connections_received:1,
migrate_cached_sockets:0
]

关于spring - Redis缓存内存状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56784239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com