Skip to content

Instantly share code, notes, and snippets.

@trydionel
Created February 27, 2010 21:17
Show Gist options
  • Save trydionel/316957 to your computer and use it in GitHub Desktop.
Save trydionel/316957 to your computer and use it in GitHub Desktop.
Lightning-Quick Redis 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 "/:key" do
@key = params[:key]
@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