riedi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Joshua Bussdieker
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Riedi
2
+
3
+ HA Distributed Key Value Engine
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'riedi'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install riedi
18
+
19
+ ## Usage
20
+
21
+ riedi-server
22
+
23
+ Get server status
24
+
25
+ curl localhost:8080/status
26
+
27
+ Set a value
28
+
29
+ curl localhost:8080/store/some_key -XPOST -d 'value=some_value'
30
+
31
+ Get a value
32
+
33
+ curl localhost:8080/store/some_key
34
+
35
+ Delete a value
36
+
37
+ curl localhost:8080/store/some_key -XDELETE
38
+
39
+ List all keys
40
+
41
+ curl localhost:8080/keys
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = ["-c", "-f d"]
6
+ end
7
+
8
+ task :test => :spec
data/bin/riedi-server ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require 'riedi'
3
+ require 'rack'
4
+
5
+ Rack::Handler::WEBrick.run(Riedi::Server, {}) do |server|
6
+ [:INT, :TERM].each { |sig| trap(sig) { server.stop } }
7
+ end
data/lib/riedi.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "riedi/version"
2
+ require "riedi/storage"
3
+ require "riedi/server"
4
+
5
+ module Riedi
6
+ end
@@ -0,0 +1,45 @@
1
+ require 'sinatra'
2
+ require 'json'
3
+
4
+ module Riedi
5
+ class Server < Sinatra::Base
6
+ def initialize(options = {})
7
+ @storage = Storage.new(options)
8
+ super
9
+ end
10
+
11
+ get '/' do
12
+ 'Riedi (try /status)'
13
+ end
14
+
15
+ get '/status' do
16
+ @storage.status
17
+ end
18
+
19
+ get '/keys' do
20
+ @storage.keys.to_json
21
+ end
22
+
23
+ post '/store/:key' do
24
+ @storage.set(params[:key], params[:value])
25
+ end
26
+
27
+ get '/store/:key' do
28
+ value = @storage.get(params[:key])
29
+ if value
30
+ value
31
+ else
32
+ error 404
33
+ end
34
+ end
35
+
36
+ delete '/store/:key' do
37
+ count = @storage.del(params[:key])
38
+ if count > 0
39
+ count.to_s
40
+ else
41
+ error 404
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,44 @@
1
+ require 'redis'
2
+
3
+ module Riedi
4
+ class Storage
5
+ def initialize(options = {})
6
+ @options = options
7
+ end
8
+
9
+ def flushall
10
+ redis.flushall
11
+ end
12
+
13
+ def status
14
+ begin
15
+ redis.randomkey
16
+ "OK"
17
+ rescue
18
+ "NG"
19
+ end
20
+ end
21
+
22
+ def keys
23
+ redis.keys
24
+ end
25
+
26
+ def set(key, value)
27
+ redis.set(key, value)
28
+ end
29
+
30
+ def get(key)
31
+ redis.get(key)
32
+ end
33
+
34
+ def del(key)
35
+ redis.del(key)
36
+ end
37
+
38
+ private
39
+
40
+ def redis
41
+ @redis ||= Redis.new(@options)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Riedi
2
+ VERSION = "0.0.1"
3
+ end
data/riedi.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'riedi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "riedi"
8
+ spec.version = Riedi::VERSION
9
+ spec.authors = ["Joshua Bussdieker"]
10
+ spec.email = ["jbussdieker@gmail.com"]
11
+ spec.summary = %q{HA Distributed Key Value Engine}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rack-test"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.add_runtime_dependency "redis", "~> 3.0.4"
26
+ spec.add_runtime_dependency "sinatra"
27
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+ require 'riedi/server'
3
+
4
+ describe Riedi::Server do
5
+ before do
6
+ @storage = Riedi::Storage.new
7
+ @storage.flushall
8
+ @storage.set("key", "value")
9
+ end
10
+
11
+ def app
12
+ Riedi::Server
13
+ end
14
+
15
+ it "GET /status" do
16
+ get "/status" do
17
+ last_response.status.should be(200)
18
+ last_response.body.should eq("OK")
19
+ end
20
+ end
21
+
22
+ it "GET /keys" do
23
+ get "/keys" do
24
+ last_response.status.should be(200)
25
+ last_response.body.should eq("[\"key\"]")
26
+ end
27
+ end
28
+
29
+ it "POST /store/key" do
30
+ post "/store/key", "value=value" do
31
+ last_response.status.should be(200)
32
+ last_response.body.should eq("OK")
33
+ end
34
+ end
35
+
36
+ it "GET /store/key" do
37
+ get "/store/key" do
38
+ last_response.status.should be(200)
39
+ last_response.body.should eq("value")
40
+ end
41
+ end
42
+
43
+ it "GET /store/missing" do
44
+ get "/store/missing" do
45
+ last_response.status.should be(404)
46
+ last_response.body.should eq("")
47
+ end
48
+ end
49
+
50
+ it "DELETE /store/key" do
51
+ delete "/store/key" do
52
+ last_response.status.should be(200)
53
+ last_response.body.should eq("1")
54
+ end
55
+ end
56
+
57
+ it "DELETE /store/missing" do
58
+ delete "/store/missing" do
59
+ last_response.status.should be(404)
60
+ last_response.body.should eq("")
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'riedi/storage'
3
+
4
+ describe Riedi::Storage do
5
+ before do
6
+ @storage = Riedi::Storage.new
7
+ @storage.flushall
8
+ @storage.set("key", "value")
9
+ end
10
+
11
+ it "status" do
12
+ @storage.status.should eql("OK")
13
+ end
14
+
15
+ it "keys" do
16
+ @storage.keys.should eql(["key"])
17
+ end
18
+
19
+ it "set" do
20
+ @storage.set("key", "test").should eql("OK")
21
+ end
22
+
23
+ it "get" do
24
+ @storage.get("key").should eql("value")
25
+ end
26
+
27
+ it "get missing" do
28
+ @storage.get("missing").should eql(nil)
29
+ end
30
+
31
+ it "del" do
32
+ @storage.del("key").should eql(1)
33
+ end
34
+
35
+ it "del missing" do
36
+ @storage.del("missing").should eql(0)
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ require 'rack/test'
2
+
3
+ RSpec.configure do |conf|
4
+ conf.include Rack::Test::Methods
5
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riedi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joshua Bussdieker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rack-test
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: redis
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 3.0.4
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 3.0.4
94
+ - !ruby/object:Gem::Dependency
95
+ name: sinatra
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description:
111
+ email:
112
+ - jbussdieker@gmail.com
113
+ executables:
114
+ - riedi-server
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - bin/riedi-server
124
+ - lib/riedi.rb
125
+ - lib/riedi/server.rb
126
+ - lib/riedi/storage.rb
127
+ - lib/riedi/version.rb
128
+ - riedi.gemspec
129
+ - spec/riedi/server_spec.rb
130
+ - spec/riedi/storage_spec.rb
131
+ - spec/spec_helper.rb
132
+ homepage: ''
133
+ licenses:
134
+ - MIT
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ segments:
146
+ - 0
147
+ hash: -149864606269020232
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ segments:
155
+ - 0
156
+ hash: -149864606269020232
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 1.8.25
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: HA Distributed Key Value Engine
163
+ test_files:
164
+ - spec/riedi/server_spec.rb
165
+ - spec/riedi/storage_spec.rb
166
+ - spec/spec_helper.rb