Permalink
Browse files

Browser for Redis keys

  • Loading branch information...
1 parent 36ef7f3 commit 73c9c79b6ad3d64a56468a01137a67bd930c8560 @tarcieri tarcieri committed Dec 21, 2012
View
8 app/controllers/stats_controller.rb
@@ -4,4 +4,12 @@ class StatsController < ApplicationController
def index
redirect_to :action => 'resque'
end
+
+ def keys
+ if params[:id]
+ render 'key'
+ else
+ render 'keys'
+ end
+ end
end
View
4 app/helpers/application_helper.rb
@@ -34,11 +34,11 @@ def pagination(options = {})
markup = ""
if start - per_page >= 0
- markup << link_to(raw("&laquo; less"), params.merge(:start => start - per_page), :class => 'less')
+ markup << link_to(raw("&laquo; less"), params.merge(:start => start - per_page), :class => 'btn less')
end
if start + 20 <= total
- markup << link_to(raw("&raquo; more"), params.merge(:start => start + per_page), :class => 'more')
+ markup << link_to(raw("more &raquo;"), params.merge(:start => start + per_page), :class => 'btn more')
end
content_tag :p, raw(markup), :class => 'pagination'
View
25 app/helpers/stats_helper.rb
@@ -7,8 +7,12 @@ def redis_info
Resque.redis.info.to_a.sort_by { |i| i[0].to_s }
end
- def key_size(key)
- case Resque.redis.type(key)
+ def redis_key_type(key)
+ Resque.redis.type(key)
+ end
+
+ def redis_key_size(key)
+ case redis_key_type(key)
when 'none'
0
when 'list'
@@ -22,6 +26,23 @@ def key_size(key)
end
end
+ def redis_get_array(key, start=0)
+ case redis_key_type(key)
+ when 'none'
+ []
+ when 'list'
+ Resque.redis.lrange(key, start, start + 20)
+ when 'set'
+ Resque.redis.smembers(key)[start..(start + 20)]
+ when 'string'
+ [Resque.redis.get(key)]
+ when 'zset'
+ Resque.redis.zrange(key, start, start + 20)
+ when 'hash'
+ Resque.redis.hgetall(key)
+ end
+ end
+
def current_subtab?(name)
params[:action] == name.to_s
end
View
26 app/views/stats/key.html.erb
@@ -0,0 +1,26 @@
+<% if redis_key_type(params[:key]) == 'string' %>
+ <h1>Key "<%= params[:id] %>" is a string</h1>
+ <h2>size: <%= redis_key_size(params[:id]) %></h2>
+ <table class="table table-bordered">
+ <tr>
+ <td><%= redis_get_array(key) %></td>
+ </tr>
+ </table>
+<% else %>
+ <p class="sub">
+ Showing <%= start = params[:start].to_i %> to <%= start + 20 %> of <b><%=size = redis_key_size(params[:id]) %></b>
+ </p>
+
+ <h1>Key "<%= params[:id] %>" is a <%= redis_key_type(params[:id]) %></h1>
+ <table class="table table-bordered">
+ <% redis_get_array(params[:id], start).each do |row| %>
+ <tr>
+ <td>
+ <%= row %>
+ </td>
+ </tr>
+ <% end %>
+ </table>
+
+ <%= pagination :start => start, :total => size %>
+<% end %>
View
4 app/views/stats/keys.html.erb
@@ -12,8 +12,8 @@
<th>
<%= link_to key, "/stats/keys/#{key}" %>
</th>
- <td><%= Resque.redis.type key %></td>
- <td><%= key_size key %></td>
+ <td><%= redis_key_type key %></td>
+ <td><%= redis_key_size key %></td>
</tr>
<% end %>
</table>
View
1 config/routes.rb
@@ -17,6 +17,7 @@
get '/stats' => "stats#index"
get '/stats/:action', :controller => :stats
+ get '/stats/:action/:id', :controller => :stats, :constraints => {:id => id_pattern}
root :to => 'overview#show'
end

0 comments on commit 73c9c79

Please sign in to comment.