RSS Git Download  Clone
Raw Blame History 584B 22 lines
const Redis = require('ioredis')
const redisInfo = require('redis-info')
const hash = require('object-hash')

const redisInfoCache = {}
module.exports = async function getInfo(server, options={}){
    const {
      cache = false,
      force = false,
    } = options
    const id = cache ? hash(server) : null
    if(cache && !force && redisInfoCache[id]){
        return redisInfoCache[id]
    }
    const redis = new Redis(server)
    const rawInfo = await redis.info()
    const info = redisInfo.parse(rawInfo)
    if(cache){
      redisInfoCache[id] = info
    }
    return info
}