Skip to content

Instantly share code, notes, and snippets.

@jasoares
Created April 3, 2017 00:59
Show Gist options
  • Save jasoares/ab5fd915ccc9e90d208b1ad310f57655 to your computer and use it in GitHub Desktop.
Save jasoares/ab5fd915ccc9e90d208b1ad310f57655 to your computer and use it in GitHub Desktop.
Redis Contents Describer
$redis = Redis.new
keys = $redis.keys('*')
keys_with_values = keys.inject({}) do |kwv, key|
type = $redis.type(key)
value = $redis.get(key) if type == 'string'
value = $redis.scard(key) if type == 'set'
value = $redis.hkeys(key) if type == 'hash'
value = $redis.llen(key) if type == 'list'
value = $redis.zcard(key) if type == 'zset'
kwv[key] = { type: type, value: value }
kwv
end
ap keys_with_values.sort { |(k1, v1), (k2, v2)| v1[:type] <=> v2[:type] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment