-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 116c525
Showing
29 changed files
with
1,094 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
bin/* | ||
vendor/* | ||
redis.yml | ||
rerun.txt | ||
webrat.log |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
source "http://gems.github.com" | ||
source "http://gemcutter.org" | ||
|
||
bundle_path "vendor/gems" | ||
|
||
gem "sinatra", "0.9.4" | ||
gem "rack", "1.1" | ||
|
||
gem "redis", "0.1.1" | ||
|
||
only :test do | ||
gem "cucumber", "0.6.1" | ||
gem "rack-test", "0.5.3", :require_as => "rack/test" | ||
gem "rspec", "1.3.0" | ||
gem "test-unit", "1.2.3" | ||
gem "webrat", "0.6.0" | ||
end | ||
|
||
disable_system_gems |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Shredis | ||
======= | ||
|
||
Shredis is a simple show-me-what-you-got-Redis application written using Sinatra, aiming to become a Ruby equivalent of phpMyAdmin for Redis. | ||
|
||
Tested with Ruby 1.9.1p378 (2010-01-10 revision 26273). | ||
|
||
Usage | ||
----- | ||
|
||
`git clone git://github.com/filiptepper/shredis.git | ||
cd shredis | ||
gem install bundler | ||
gem bundle | ||
cp redis.yml.exmaple redis.yml` | ||
|
||
Edit `redis.yml`. | ||
|
||
`./bin/rackup` | ||
|
||
Browse to `http://localhost:9292/`. | ||
|
||
Contributing | ||
------------ | ||
|
||
Contributions are welcome! | ||
|
||
To contribute: | ||
|
||
* fork, | ||
* spec, | ||
* code, | ||
* request pull. | ||
|
||
Issues | ||
------ | ||
|
||
Please report all issues via GitHub's issue tracker at [http://github.com/filiptepper/shredis/issues](http://github.com/filiptepper/shredis/issues). | ||
|
||
What needs to be done | ||
--------------------- | ||
|
||
Shredis is a work in constant progress. | ||
|
||
Coming up: | ||
|
||
* better configuration, | ||
* search, | ||
* paging. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Shredis | ||
module DatabasesController | ||
|
||
get "/databases" do | ||
@databases = Shredder.databases | ||
erb :"databases/index" | ||
end | ||
|
||
get "/databases/:id" do | ||
@database = Shredder.databases.include?(params[:id]) ? params[:id] : nil | ||
|
||
unless @database.nil? | ||
Shredder.db = @database | ||
@keys = Shredder.keys "*" | ||
end | ||
|
||
erb :"databases/show" | ||
end | ||
|
||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module Shredis | ||
module Helpers | ||
|
||
def time_distance(time) | ||
case time | ||
|
||
when 1..59 | ||
"#{time} second#{s time}" | ||
|
||
when 60..3599 | ||
minutes = (time / 60).floor | ||
seconds = time % 60 | ||
"#{minutes} minute#{s minutes}" + | ||
(seconds > 0 ? " #{seconds} second#{s seconds}" : "") | ||
|
||
when 3600..86399 | ||
hours = (time / 3600).floor | ||
minutes = ((time % 3600) / 60).floor | ||
seconds = time % 60 | ||
"#{hours} hour#{s hours}" + | ||
(minutes > 0 ? " #{minutes} minute#{s minutes}" : "") + | ||
(seconds > 0 ? " #{seconds} second#{s seconds}" : "") | ||
|
||
when 86400..1.0/0 | ||
days = (time / 86400).floor | ||
hours = ((time % 86400) / 3600).floor | ||
minutes = ((time % 3600) / 60).floor | ||
seconds = time % 60 | ||
"#{days} day#{s days}" + | ||
(hours > 0 ? " #{hours} hour#{s hours}" : "") + | ||
(minutes > 0 ? " #{minutes} minute#{s minutes}" : "") + | ||
(seconds > 0 ? " #{seconds} second#{s seconds}" : "") | ||
|
||
end | ||
|
||
end | ||
|
||
def file_size(size) | ||
case size | ||
|
||
when (1024...1024 ** 2) | ||
"#{format("%.2f", (size / 1024.to_f))} KB" | ||
|
||
when (1024 ** 2...1024 ** 3) | ||
"#{format("%.2f", (size / 1024 ** 2.to_f))} MB" | ||
|
||
when (1024 ** 3...1.0/0) | ||
"#{format("%.2f", (size / 1024 ** 3.to_f))} GB" | ||
|
||
end | ||
end | ||
|
||
|
||
private | ||
|
||
|
||
def s(number) | ||
number == 1 ? "" : "s" | ||
end | ||
|
||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Shredis | ||
module HomepageController | ||
|
||
get "/" do | ||
if Shredder.databases.length == 1 | ||
redirect "/databases/#{Shredder.databases[0]}" | ||
else | ||
redirect "/databases" | ||
end | ||
end | ||
|
||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Shredis | ||
module KeysController | ||
|
||
get "/databases/:database_id/keys/:id" do | ||
@database = Shredder.databases.include?(params[:database_id]) ? params[:database_id] : nil | ||
@key = params[:id] | ||
|
||
unless @database.nil? | ||
case Shredder.type params[:id] | ||
|
||
when "list" | ||
@value = Shredder.lrange @key, 0, Shredder.llen(@key) - 1 | ||
|
||
when "set" | ||
@value = Shredder.smembers @key | ||
|
||
when "zset" | ||
@value = Shredder.zrange @key, 0, Shredder.zcard(@key) - 1 | ||
|
||
when "string" | ||
@value = Shredder.get @key | ||
|
||
end | ||
end | ||
|
||
erb :"keys/show" | ||
end | ||
|
||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "rubygems" | ||
require "sinatra" | ||
|
||
set :run, false | ||
set :environment, ENV["RACK_ENV"] || "development" | ||
|
||
require "shredis" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<% | ||
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" | ||
rerun_opts = rerun.to_s.strip.empty? ? "--format progress features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" | ||
std_opts = "#{rerun_opts} --format rerun --out rerun.txt --strict --tags ~@wip" | ||
%> | ||
default: <%= std_opts %> | ||
wip: --tags @wip:3 --wip features |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Feature: Shredis Homepage | ||
In order to browse Redis databases | ||
I want to be redirected to databases list or default database | ||
|
||
Scenario: Empty database | ||
Given an empty Redis database | ||
When I go to the homepage | ||
Then I should see "No databases." | ||
|
||
Scenario: One database | ||
Given Redis database 3 | ||
When I go to the homepage | ||
Then I should see "Current database: #3" | ||
|
||
Scenario: More databases | ||
Given Redis databases 1, 2 | ||
When I go to the homepage | ||
Then I should see "#1" | ||
And I should see "#2" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Feature: Browse Redis Database Keys | ||
In order to browse Redis database keys | ||
I want to list current Redis database keys | ||
|
||
Scenario: Empty Database | ||
Given empty Redis database 15 | ||
When I go to the page of database 15 keys | ||
Then I should see "Database doesn't exist." | ||
|
||
Scenario: Database With Keys | ||
Given Redis database 15 | ||
When I go to the page of database 15 | ||
Then I should see "shredder:key:15" | ||
|
||
Scenario: Databases With Keys | ||
Given Redis databases 14, 15 | ||
When I go to the homepage | ||
When I follow "#14" | ||
Then I should see "shredder:key:14" | ||
|
||
Scenario: Non-Existing Key | ||
Given Redis database 15 | ||
When I go to the page of database's 15 key "shredder:key:51" | ||
Then I should see "Key doesn't exist." | ||
|
||
Scenario: String Key | ||
Given Redis database 15 | ||
And Redis string key "string:key" with value "my-string" | ||
When I go to the page of database 15 | ||
When I follow "string:key" | ||
Then I should see "my-string" | ||
|
||
Scenario: List Key | ||
Given Redis database 15 | ||
And Redis list key "list:key" with values "my-list-1, my-list-2, my-list-3" | ||
When I go to the page of database 15 | ||
When I follow "list:key" | ||
Then I should see "my-list-1" | ||
And I should see "my-list-2" | ||
And I should see "my-list-3" | ||
|
||
Scenario: Set Key | ||
Given Redis database 15 | ||
And Redis set key "set:key" with values "my-set-1, my-set-2, my-set-3" | ||
When I go to the page of database 15 | ||
When I follow "set:key" | ||
Then I should see "my-set-1" | ||
And I should see "my-set-2" | ||
And I should see "my-set-3" | ||
|
||
Scenario: Sorted Set Key | ||
Given Redis database 15 | ||
And Redis sorted set key "zset:key" with values "my-zset-1, my-zset-2, my-zset-3" | ||
When I go to the page of database 15 | ||
When I follow "zset:key" | ||
Then I should see "my-zset-1" | ||
And I should see "my-zset-2" | ||
And I should see "my-zset-3" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Feature: Manage Redis Databases | ||
In order to browse Redis databases | ||
I want to list Redis databases | ||
|
||
Scenario: Empty Databases List | ||
Given an empty Redis database | ||
When I go to the list of databases | ||
Then I should see "No databases." | ||
|
||
Scenario: Current Databases List | ||
Given Redis databases 3, 6, 9 | ||
When I go to the list of databases | ||
Then I should see "#3" | ||
And I should see "#6" | ||
And I should see "#9" | ||
|
||
Scenario: Wrong Database | ||
Given Redis databases 1, 2, 3 | ||
When I go to the page of database 4 | ||
Then I should see "Database doesn't exist." |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Feature: Redis Database Status | ||
In order to check current Redis database status | ||
I want to display INFO command value | ||
|
||
Scenario: Homepage | ||
Given an empty Redis database | ||
When I go to the homepage | ||
Then I should see "Status" | ||
And I should see "Redis" | ||
And I should see "Uptime" | ||
And I should see "Connected clients" | ||
And I should see "Used memory" | ||
And I should see "Last save time" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
Given /^an empty Redis database$/ do | ||
Shredder.flushall | ||
end | ||
|
||
Given /^Redis database[s]? ([0-9,\s]*)$/ do |databases| | ||
databases = databases.split(",").map { |database| database.strip } | ||
|
||
Shredder.flushall | ||
databases.each do |database| | ||
Shredder.db = database | ||
Shredder.set "shredder:key:#{database}", "shredder:value:#{database}" | ||
end | ||
end | ||
|
||
Given /^empty Redis database[s]? ([0-9,\s]*)$/ do |databases| | ||
databases = databases.split(",").map { |database| database.strip } | ||
|
||
Shredder.flushall | ||
databases.each do |database| | ||
Shredder.db = database | ||
Shredder.set "shredder:key:#{database}", "shredder:value:#{database}" | ||
Shredder.del "shredder:key:#{database}" | ||
end | ||
end | ||
|
||
Given /^Redis string key "([^\"]*)" with value "([^\"]*)"$/ do |key, value| | ||
Shredder.set key, value | ||
end | ||
|
||
Given /^Redis list key "([^\"]*)" with values "([^\"]*)"$/ do |key, values| | ||
values.split(",").each do |value| | ||
Shredder.lpush key, value | ||
end | ||
end | ||
|
||
Given /^Redis set key "([^\"]*)" with values "([^\"]*)"$/ do |key, values| | ||
values.split(",").each do |value| | ||
Shredder.sadd key, value | ||
end | ||
end | ||
|
||
Given /^Redis sorted set key "([^\"]*)" with values "([^\"]*)"$/ do |key, values| | ||
values.split(",").each do |value| | ||
Shredder.zadd key, value, value | ||
end | ||
end |
Oops, something went wrong.