gpt4 book ai didi

ruby - 通过 Ruby 获取 Redis 状态

转载 作者:IT王子 更新时间:2023-10-29 06:05:09 34 4
gpt4 key购买 nike

我想使用 Ruby 脚本检索 Redis 状态,我尝试了以下命令:

redis_status_command, stdeerr, status = Open3.capture3(`redis-cli -h 127.0.0.1 -p 6379 info|grep status`)

redis_status_command, stdeerr, status = Open3.capture3(`systemctl status redis`)

然后,当我尝试打印变量 redis_status_command 时,它返回一个空格,但我知道 Open3.capture3 部分中的命令在命令中起作用线。如何使用 Ruby 检索 Redis 状态?谢谢

最佳答案

使用“redis”gem,您可以获得如下所有信息属性:

require 'redis'
client = Redis.new(
url: "redis://your-host.your-domain.com",
port: 6379
)
client.info

输出将是信息的哈希值:

{
"redis_version" => "3.2.4",
"redis_git_sha1" => "0",
"redis_git_dirty" => "0",
"redis_build_id" => "0",
"redis_mode" => "standalone",
"os" => "Amazon ElastiCache",
"arch_bits" => "64",
"multiplexing_api" => "epoll",
"gcc_version" => "0.0.0",
"process_id" => "1",
"run_id" => "73f5f76133b7bfd66eb89850a2f9df43e838f567",
"tcp_port" => "6379",
"uptime_in_seconds" => "1754115",
"uptime_in_days" => "20",
"hz" => "10",
"lru_clock" => "5884700",
"executable" => "-",
"config_file" => "-",
"connected_clients" => "10",
"client_longest_output_list" => "0",
"client_biggest_input_buf" => "0",
"blocked_clients" => "0",
"used_memory" => "16110168",
"used_memory_human" => "15.36M",
"used_memory_rss" => "19808256",
"used_memory_rss_human" => "18.89M",
"used_memory_peak" => "19915496",
"used_memory_peak_human" => "18.99M",
"used_memory_lua" => "37888",
"used_memory_lua_human" => "37.00K",
"maxmemory" => "6501171200",
"maxmemory_human" => "6.05G",
"maxmemory_policy" => "volatile-lru",
"mem_fragmentation_ratio" => "1.23",
"mem_allocator" => "jemalloc-4.0.3",
"loading" => "0",
"rdb_changes_since_last_save" => "30264",
"rdb_bgsave_in_progress" => "0",
"rdb_last_save_time" => "1497302809",
"rdb_last_bgsave_status" => "ok",
"rdb_last_bgsave_time_sec" => "-1",
"rdb_current_bgsave_time_sec" => "-1",
"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",
"total_connections_received" => "29746",
"total_commands_processed" => "3809776",
"instantaneous_ops_per_sec" => "1",
"total_net_input_bytes" => "382270539",
"total_net_output_bytes" => "3134102675",
"instantaneous_input_kbps" => "0.05",
"instantaneous_output_kbps" => "0.03",
"rejected_connections" => "0",
"sync_full" => "1",
"sync_partial_ok" => "0",
"sync_partial_err" => "0",
"expired_keys" => "0",
"evicted_keys" => "0",
"keyspace_hits" => "674",
"keyspace_misses" => "318",
"pubsub_channels" => "0",
"pubsub_patterns" => "0",
"latest_fork_usec" => "162",
"migrate_cached_sockets" => "0",
"role" => "master",
"connected_slaves" => "1",
"slave0" => "ip=192.168.1.2,port=6379,state=online,offset=341359205,lag=0",
"master_repl_offset" => "341359205",
"repl_backlog_active" => "1",
"repl_backlog_size" => "1048576",
"repl_backlog_first_byte_offset" => "340310630",
"repl_backlog_histlen" => "1048576",
"used_cpu_sys" => "494.00",
"used_cpu_user" => "912.16",
"used_cpu_sys_children" => "0.00",
"used_cpu_user_children" => "0.00",
"cluster_enabled" => "0",
"db0" => "keys=3479,expires=0,avg_ttl=0"
}

关于ruby - 通过 Ruby 获取 Redis 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44871749/

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