-
-
Save emischorr/3181127 to your computer and use it in GitHub Desktop.
A fast sinatra redis data viewer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.unshift File.dirname(__FILE__) | |
require 'app' | |
run Sinatra::Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%html | |
%body | |
%h1 Current Keys | |
%ul | |
[email protected] do |key| | |
%li | |
%a{:href => "/#{key}"}= key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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