Read more

How to pretty print all values in a Redis database

Emanuel
July 10, 2023Software engineer at makandra GmbH

With this Ruby script you can print all values in a Redis database to your console (derived from this bash script Show archive.org snapshot ).

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Note: Do not run this command in production. This is for debugging purposes only.

def pretty_print_redis(redis)
  redis.keys.each_with_object({}) do |key, hash|
    type = redis.type(key)

    hash[key] = case type
    when 'string'
      redis.get(key)
    when 'hash'
      redis.hgetall(key)
    when 'list'
      redis.lrange(key, 0, -1)
    when 'set'
      redis.smembers(key)
    when 'zset'
      redis.zrange(key, 0, -1, with_scores: true)
    else
      raise ArgumentError, "Unknown type #{type}"
    end
  end
end

pretty_print_redis(Redis.new(host: "10.0.1.1", port: 6380, db: 15))
Posted by Emanuel to makandra dev (2023-07-10 15:27)