Reputation: 3635
Following documentation from, https://redis.io/commands/info
I want to get specific key/values from returned bulk string
For example:
# 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
.....
I want to only get used_memory and so on.
Is it possible without using Ruby tweaks?
ALSO how can I use MEMORY DOCTOR
to get information, given I have initialized the Redis in my controller? (e.g redis = Redis.new(host: 'localhost', port: 6379)
)
https://redis.io/commands/memory-doctor
Thanks in advance!
Upvotes: 2
Views: 745
Reputation: 13014
Use Hash#slice
to get relevant key-value pairs
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
Upvotes: 2