Skip to content

Instantly share code, notes, and snippets.

@locks

locks/Gemfile Secret

Created September 3, 2011 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save locks/1c2302b76484e559b125 to your computer and use it in GitHub Desktop.
Save locks/1c2302b76484e559b125 to your computer and use it in GitHub Desktop.
Chester

Massive
Multiplayer
Online
Ephemeral
Key
Value
Storage

MMO

It's meant to be run on a simple Heroku instance, and anyone can pitch in key/value pairs

Ephemeral

Besides the obvious effects of anyone being able to access and modify the data, everything is stored in memory with no hard persistance. This is by design.

So, whenever the instances restarts or goes down, so does everything in it. This is subject to change in the future.

KVS

You store a value associated with a key. That's it.

The End

The app contains instructions on how to move data in and out.

Basically just use HTTP methods and you're golden.

require 'sinatra'
require 'haml'
require 'json'
# initial data just to have something to fiddle with
configure do
set :storage, { 'init' => 'all' , 'dumb' => 'dumber' }
end
get '/' do
@store = settings.storage
haml :index
end
get '/keys' do
settings.storage.keys.join("\n")
end
get '/:key' do
key = params[:key].strip
stg = settings.storage
stg.has_key?(key) ? stg[key] : ""
end
post '/:key' do
key = params[:key].strip
value = request.body.read
value.empty? ? "" : settings.storage[key] = value
end
delete '/:key' do
key = params[:key].strip
settings.storage.delete(key) if settings.storage.has_key?(key)
end
__END__
@@ index
%html
%head
%title Chester :: MMOEKVS
%body{:style=>"text-align: center;"}
%h1 Chester, the MMOEKVS
(Massive Multiplayer Online Ephemeral Key Value Storage)
%h2 Never Trust The Cloud.
%table{:style=>"background:#DDD; margin:auto;"}
%tr
%td
%strong SET
%td curl -d "[value]" http://chester.heroku.com/[key]
%tr
%td
%strong GET
%td curl http://chester.heroku.com/[key]
%tr
%td
%strong KEYS
%td curl http://chester.heroku.com/keys
%tr
%td
%strong DELETE
%td curl -X DELETE http://chester.heroku.com/[key
%table{:style => "margin: 2em auto;"}
%tr
%td Key
%td Value
- @store.each do |k,v|
%tr
%td= k
%td= v
require 'rubygems'
require './app.rb'
use Rack::ShowExceptions
run Sinatra::Application
source :rubygems
gem 'sinatra'
gem 'haml'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment