Skip to content

Instantly share code, notes, and snippets.

@shiftb
Forked from trydionel/app.rb
Created March 20, 2011 23:52
Show Gist options
  • Save shiftb/878800 to your computer and use it in GitHub Desktop.
Save shiftb/878800 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.new
end
end
get "/" do
@keys = redis.keys("*")
haml :index
end
get "/*" do
@key = params[:splat].first
@data = case redis.type(@key)
when "string"
Array(redis[@key])
when "list"
redis.lrange(@key, 0, -1)
when "set"
redis.set_members(@key)
else
[]
end
haml :show
end
%html
%body
%h1 Current Keys
%ul
-@keys.each do |key|
%li
%a{:href => "/#{key}"}= key
%html
%body
%h1= "Data stored in '#{@key}'"
%ul
-@data.each do |data|
%li
%p= data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment