ruby-on-rails - 如何从 Redis INFO 获取特定值
问题描述
遵循来自https://redis.io/commands/info的文档
我想从返回的特定键/值bulk string
例如:
# Rails Controller Code
redis = Redis.new(host: 'localhost', port: 6379)
render json: redis.INFO
... returns ....
# Server
redis_version:999.999.999
redis_git_sha1:3c968ff0
redis_git_dirty:0
......
......
# Memory
used_memory:167560008
used_memory_human:159.80M
used_memory_rss:174358528
used_memory_rss_human:166.28M
.....
我只想得到used_memory等等。
是否可以不使用 Ruby 调整?
MEMORY DOCTOR
另外,鉴于我已经在控制器中初始化了 Redis,我该如何使用它来获取信息?(例如redis = Redis.new(host: 'localhost', port: 6379)
)
https://redis.io/commands/memory-doctor
提前致谢!
解决方案
用于Hash#slice
获取相关键值对
redis = Redis.new(host: 'localhost', port: 6379)
redis.info #=> returns hash
result = redis.info.slice('used_memory_human', 'used_memory_rss')
#=> {"used_memory_human"=>"1.10M", "used_memory_rss"=>"700416"}
render json: result
推荐阅读
- javascript - React Native Expo - 渲染后将 Scrollview 重置为 ScrollView 的顶部
- r - 如何告诉 geom_rect 由 geom_col 放置的条的位置
- angular - 如何将 SVG 图标与 ContextMenu 等 Syncfusion 组件一起使用?
- node.js - 负鼠断路器 NodeJS -
- android - 使用vscode开发一个flutter应用,但是在手机上停止调试打开应用后,加载了之前的版本
- api - Google Translation API 在中文和非中文字符之间添加空格
- html - 如何根据 div 大小在 div 上方动态添加文本
- r - R:如何在函数中调用 feols 回归
- dns - dns中的重复记录名称
- amazon-redshift - redshift_connector 教程代码出现异常:收到的数字类型的列值格式错误