Skip to content

Instantly share code, notes, and snippets.

@emischorr
Forked from dunedain289/app.rb
Created July 26, 2012 09:06
Show Gist options
  • Save emischorr/3181127 to your computer and use it in GitHub Desktop.
Save emischorr/3181127 to your computer and use it in GitHub Desktop.
A fast sinatra redis data viewer
require 'rubygems'
require 'haml'
require 'sinatra'
require 'redis'
helpers do
def redis
@redis ||= Redis.connect
end
end
get "/" do
@keys = redis.keys("*").sort
haml :index
end
get "/*" do
@key = params[:splat].first
@type = redis.type(@key)
@data = case @type
when "string"
Array(redis[@key])
when "list"
redis.lrange(@key, 0, -1)
when "set"
redis.smembers(@key)
when "hash"
redis.hgetall(@key).sort
when "zset"
redis.zrange(@key, 0, -1, :with_scores => true)
else
[]
end
haml :show
end
$:.unshift File.dirname(__FILE__)
require 'app'
run Sinatra::Application
%html
%body
%h1 Current Keys
%ul
[email protected] do |key|
%li
%a{:href => "/#{key}"}= key
%html
%body
%h1= "Data stored in '#{@key}'"
%h2
Size:
= @data.length
- if @type == "string" || @type == "list" || @type == "set"
%ul
[email protected] do |data|
%li
%p= data
- else
%dl
- @data.each_slice(2) do |k,v|
%dt= k
%dd= v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment