iron_cache 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +52 -0
- data/Rakefile +40 -0
- data/VERSION.yml +5 -0
- data/iron_cache.gemspec +61 -0
- data/lib/iron_cache/caches.rb +80 -0
- data/lib/iron_cache/client.rb +152 -0
- data/lib/iron_cache/items.rb +93 -0
- data/lib/iron_cache.rb +3 -0
- data/test/Gemfile +4 -0
- data/test/Gemfile.lock +38 -0
- data/test/quick_run.rb +33 -0
- data/test/test_base.rb +52 -0
- data/test/test_iron_cache.rb +59 -0
- data/test/test_memcached.rb +59 -0
- metadata +103 -0
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
IronMQ Ruby Client
|
2
|
+
-------------
|
3
|
+
|
4
|
+
Getting Started
|
5
|
+
==============
|
6
|
+
|
7
|
+
Install the gem:
|
8
|
+
|
9
|
+
gem install iron_cache
|
10
|
+
|
11
|
+
Create an IronMQ client object:
|
12
|
+
|
13
|
+
@iron_cache = IronCache::Client.new(:token=>'MYTOKEN', :project_id=>'MYPROJECTID')
|
14
|
+
|
15
|
+
You can get your `token` and `project_id` at http://www.iron.io .
|
16
|
+
|
17
|
+
|
18
|
+
The Basics
|
19
|
+
=========
|
20
|
+
|
21
|
+
**Put** an item in the cache:
|
22
|
+
|
23
|
+
msg = @iron_cache.items.put("mykey", "hello world!")
|
24
|
+
p msg
|
25
|
+
|
26
|
+
**Get** an item from the cache:
|
27
|
+
|
28
|
+
msg = @iron_cache.items.get("mykey")
|
29
|
+
p msg
|
30
|
+
|
31
|
+
**Delete** an item from the cache:
|
32
|
+
|
33
|
+
res = msg.delete # or @iron_cache.items.delete("mykey")
|
34
|
+
p res
|
35
|
+
|
36
|
+
|
37
|
+
Queue Selection
|
38
|
+
===============
|
39
|
+
|
40
|
+
One of the following:
|
41
|
+
|
42
|
+
1. Pass `:cache_name=>'my_cache'` into IronCache::Client.new
|
43
|
+
1. `@iron_cache.cache_name = 'my_cache'`
|
44
|
+
1. Pass `:cache_name=>'my_cache'` into any post(), get(), or delete()
|
45
|
+
|
46
|
+
Queue Information
|
47
|
+
=================
|
48
|
+
|
49
|
+
cache = @iron_cache.queues.get(:name=>"my_cache")
|
50
|
+
puts "size: #{cache.size}"
|
51
|
+
|
52
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler2'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "iron_cache"
|
8
|
+
gem.summary = "Ruby client for IronCache by www.iron.io"
|
9
|
+
gem.description = "Ruby client for IronCache by www.iron.io"
|
10
|
+
gem.email = "travis@iron.io"
|
11
|
+
gem.homepage = "http://www.iron.io"
|
12
|
+
gem.authors = ["Travis Reeder"]
|
13
|
+
gem.add_dependency 'rest-client'
|
14
|
+
gem.add_dependency 'rest', '>= 0.1.2'
|
15
|
+
#gem.add_dependency 'typhoeus'
|
16
|
+
gem.required_ruby_version = '>= 1.9'
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler2"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
task :default => :test
|
31
|
+
|
32
|
+
require 'rdoc/task'
|
33
|
+
Rake::RDocTask.new do |rdoc|
|
34
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
35
|
+
|
36
|
+
rdoc.rdoc_dir = 'doc'
|
37
|
+
rdoc.title = "iron_cache #{version}"
|
38
|
+
rdoc.rdoc_files.include('README*')
|
39
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
40
|
+
end
|
data/VERSION.yml
ADDED
data/iron_cache.gemspec
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "iron_cache"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Travis Reeder"]
|
12
|
+
s.date = "2012-03-26"
|
13
|
+
s.description = "Ruby client for IronCache by www.iron.io"
|
14
|
+
s.email = "travis@iron.io"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"README.md",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION.yml",
|
22
|
+
"iron_cache.gemspec",
|
23
|
+
"lib/iron_cache.rb",
|
24
|
+
"lib/iron_cache/caches.rb",
|
25
|
+
"lib/iron_cache/client.rb",
|
26
|
+
"lib/iron_cache/items.rb",
|
27
|
+
"test/Gemfile",
|
28
|
+
"test/Gemfile.lock",
|
29
|
+
"test/quick_run.rb",
|
30
|
+
"test/test_base.rb",
|
31
|
+
"test/test_iron_cache.rb",
|
32
|
+
"test/test_memcached.rb"
|
33
|
+
]
|
34
|
+
s.homepage = "http://www.iron.io"
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.9")
|
37
|
+
s.rubygems_version = "1.8.15"
|
38
|
+
s.summary = "Ruby client for IronCache by www.iron.io"
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 0"])
|
45
|
+
s.add_runtime_dependency(%q<rest>, [">= 0.1.2"])
|
46
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 0"])
|
47
|
+
s.add_runtime_dependency(%q<rest>, [">= 0.1.2"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
50
|
+
s.add_dependency(%q<rest>, [">= 0.1.2"])
|
51
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
52
|
+
s.add_dependency(%q<rest>, [">= 0.1.2"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rest>, [">= 0.1.2"])
|
57
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
58
|
+
s.add_dependency(%q<rest>, [">= 0.1.2"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module IronCache
|
2
|
+
class Caches
|
3
|
+
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def path(options={})
|
11
|
+
path = "/projects/#{@client.project_id}/caches"
|
12
|
+
end
|
13
|
+
|
14
|
+
def list(options={})
|
15
|
+
ret = []
|
16
|
+
res, status = @client.get("#{path(options)}", options)
|
17
|
+
res.each do |q|
|
18
|
+
#p q
|
19
|
+
q = Cache.new(self, q)
|
20
|
+
ret << q
|
21
|
+
end
|
22
|
+
ret
|
23
|
+
end
|
24
|
+
|
25
|
+
# options:
|
26
|
+
# :name => can specify an alternative queue name
|
27
|
+
def get(options={})
|
28
|
+
res, status = @client.get("#{path(options)}/#{options[:name]}")
|
29
|
+
return Cache.new(self, res)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class Cache
|
36
|
+
|
37
|
+
def initialize(queues, res)
|
38
|
+
@queues = queues
|
39
|
+
@data = res
|
40
|
+
end
|
41
|
+
|
42
|
+
def raw
|
43
|
+
@data
|
44
|
+
end
|
45
|
+
|
46
|
+
def [](key)
|
47
|
+
raw[key]
|
48
|
+
end
|
49
|
+
|
50
|
+
def id
|
51
|
+
raw["id"]
|
52
|
+
end
|
53
|
+
|
54
|
+
def name
|
55
|
+
raw["name"]
|
56
|
+
end
|
57
|
+
|
58
|
+
def size
|
59
|
+
return raw["size"] if raw["size"]
|
60
|
+
return @size if @size
|
61
|
+
q = @queues.get(:name=>name)
|
62
|
+
@size = q.size
|
63
|
+
@size
|
64
|
+
end
|
65
|
+
|
66
|
+
def total_messages
|
67
|
+
return raw["total_messages"] if raw["total_messages"]
|
68
|
+
return @total_messages if @total_messages
|
69
|
+
q = @queues.get(:name=>name)
|
70
|
+
@total_messages = q.total_messages
|
71
|
+
@total_messages
|
72
|
+
end
|
73
|
+
|
74
|
+
# def delete
|
75
|
+
# @messages.delete(self.id)
|
76
|
+
# end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'logger'
|
3
|
+
require 'rest'
|
4
|
+
|
5
|
+
module IronCache
|
6
|
+
|
7
|
+
class Client
|
8
|
+
|
9
|
+
attr_accessor :token, :project_id, :cache_name, :logger,
|
10
|
+
:scheme, :host, :port
|
11
|
+
|
12
|
+
def initialize(options={})
|
13
|
+
@logger = Logger.new(STDOUT)
|
14
|
+
@logger.level=Logger::INFO
|
15
|
+
|
16
|
+
@token = options[:token] || options['token']
|
17
|
+
@project_id = options[:project_id] || options['project_id']
|
18
|
+
@cache_name = options[:cache_name] || options['cache_name'] || "default"
|
19
|
+
@scheme = options[:scheme] || options['scheme'] || "https"
|
20
|
+
@host = options[:host] || options['host'] || "cache-aws-us-east-1.iron.io"
|
21
|
+
@port = options[:port] || options['port'] || 443
|
22
|
+
|
23
|
+
@base_url = "#{@scheme}://#{@host}:#{@port}/1"
|
24
|
+
|
25
|
+
@rest = Rest::Client.new
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def items
|
30
|
+
return Items.new(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def cache
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def caches
|
38
|
+
return Caches.new(self)
|
39
|
+
end
|
40
|
+
|
41
|
+
def base_url
|
42
|
+
#"#{scheme}://#{host}:#{port}/1"
|
43
|
+
@base_url
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def full_url(path)
|
48
|
+
url = "#{base_url}#{path}"
|
49
|
+
url
|
50
|
+
end
|
51
|
+
|
52
|
+
def common_req_hash
|
53
|
+
{
|
54
|
+
:headers=>{"Content-Type" => 'application/json',
|
55
|
+
"Authorization"=>"OAuth #{@token}",
|
56
|
+
"User-Agent"=>"IronCache Ruby Client"}
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def get(path, params={})
|
61
|
+
url = full_url(path)
|
62
|
+
@logger.debug 'url=' + url
|
63
|
+
req_hash = common_req_hash
|
64
|
+
req_hash[:params] = params if params
|
65
|
+
@logger.debug 'req_hash=' + req_hash.inspect
|
66
|
+
response = @rest.get(url, req_hash)
|
67
|
+
@logger.debug 'GET response=' + response.inspect
|
68
|
+
res = check_response(response)
|
69
|
+
return res, response.code
|
70
|
+
end
|
71
|
+
|
72
|
+
def post(path, params={})
|
73
|
+
url = full_url(path)
|
74
|
+
@logger.debug 'url=' + url
|
75
|
+
#response = @http_sess.post(path + "?oauth=#{@token}", {'oauth' => @token}.merge(params).to_json, {"Content-Type" => 'application/json'})
|
76
|
+
req_hash = common_req_hash
|
77
|
+
req_hash[:body] = params.to_json
|
78
|
+
response = @rest.post(url, req_hash)
|
79
|
+
@logger.debug 'POST response=' + response.inspect
|
80
|
+
res = check_response(response)
|
81
|
+
#@logger.debug 'response: ' + res.inspect
|
82
|
+
#body = response.body
|
83
|
+
#res = JSON.parse(body)
|
84
|
+
return res, response.code
|
85
|
+
end
|
86
|
+
|
87
|
+
def put(path, params={})
|
88
|
+
url = full_url(path)
|
89
|
+
@logger.debug 'url=' + url
|
90
|
+
#response = @http_sess.post(path + "?oauth=#{@token}", {'oauth' => @token}.merge(params).to_json, {"Content-Type" => 'application/json'})
|
91
|
+
req_hash = common_req_hash
|
92
|
+
req_hash[:body] = params.to_json
|
93
|
+
response = @rest.put(url, req_hash)
|
94
|
+
@logger.debug 'POST response=' + response.inspect
|
95
|
+
res = check_response(response)
|
96
|
+
#@logger.debug 'response: ' + res.inspect
|
97
|
+
#body = response.body
|
98
|
+
#res = JSON.parse(body)
|
99
|
+
return res, response.code
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
def delete(path, params={})
|
105
|
+
url = "#{base_url}#{path}"
|
106
|
+
@logger.debug 'url=' + url
|
107
|
+
req_hash = common_req_hash
|
108
|
+
req_hash[:params] = params
|
109
|
+
response = @rest.delete(url, req_hash)
|
110
|
+
res = check_response(response)
|
111
|
+
#body = response.body
|
112
|
+
#res = JSON.parse(body)
|
113
|
+
#@logger.debug 'response: ' + res.inspect
|
114
|
+
return res, response.code
|
115
|
+
end
|
116
|
+
|
117
|
+
def check_response(response)
|
118
|
+
# response.code # http status code
|
119
|
+
#response.time # time in seconds the request took
|
120
|
+
#response.headers # the http headers
|
121
|
+
#response.headers_hash # http headers put into a hash
|
122
|
+
#response.body # the response body
|
123
|
+
status = response.code
|
124
|
+
body = response.body
|
125
|
+
# todo: check content-type == application/json before parsing
|
126
|
+
@logger.debug "response code=" + status.to_s
|
127
|
+
@logger.debug "response body=" + body.inspect
|
128
|
+
res = JSON.parse(body)
|
129
|
+
if status < 400
|
130
|
+
|
131
|
+
else
|
132
|
+
raise IronCache::Error.new(res["msg"], :status=>status)
|
133
|
+
end
|
134
|
+
res
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
class Error < StandardError
|
140
|
+
def initialize(msg, options={})
|
141
|
+
super(msg)
|
142
|
+
@options = options
|
143
|
+
end
|
144
|
+
|
145
|
+
def status
|
146
|
+
@options[:status]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
end
|
152
|
+
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module IronCache
|
2
|
+
class Items
|
3
|
+
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def path(key, options={})
|
11
|
+
path = "/projects/#{@client.project_id}/caches/#{options[:cache_name] || @client.cache_name}/items/#{key}"
|
12
|
+
end
|
13
|
+
|
14
|
+
# options:
|
15
|
+
# :queue_name => can specify an alternative queue name
|
16
|
+
# :timeout => amount of time before message goes back on the queue
|
17
|
+
def get(key, options={})
|
18
|
+
begin
|
19
|
+
res, status = @client.get(path(key, options), options)
|
20
|
+
@client.logger.debug "GET response: " + res.inspect
|
21
|
+
return Item.new(self, res)
|
22
|
+
rescue IronCache::Error => ex
|
23
|
+
if ex.status == 404
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
raise ex
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# options:
|
32
|
+
# :cache_name => can specify an alternative queue name
|
33
|
+
# :expires_in => After this delay in seconds, message will be automatically removed from the cache.
|
34
|
+
def put(key, value, options={})
|
35
|
+
to_send = options
|
36
|
+
to_send[:body] = value
|
37
|
+
res, status = @client.put(path(key, options), to_send)
|
38
|
+
#return Message.new(self, res)
|
39
|
+
return ResponseBase.new(res)
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete(key, options={})
|
43
|
+
path2 = "#{self.path(key, options)}"
|
44
|
+
res, status = @client.delete(path2)
|
45
|
+
res
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
class ResponseBase
|
51
|
+
def initialize(res)
|
52
|
+
@data = res
|
53
|
+
end
|
54
|
+
|
55
|
+
def raw
|
56
|
+
@data
|
57
|
+
end
|
58
|
+
|
59
|
+
def [](key)
|
60
|
+
raw[key]
|
61
|
+
end
|
62
|
+
|
63
|
+
def id
|
64
|
+
raw["id"]
|
65
|
+
end
|
66
|
+
|
67
|
+
def msg
|
68
|
+
raw["msg"]
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
class Item < ResponseBase
|
74
|
+
|
75
|
+
def initialize(messages, res)
|
76
|
+
super(res)
|
77
|
+
@messages = messages
|
78
|
+
end
|
79
|
+
|
80
|
+
def key
|
81
|
+
raw["key"]
|
82
|
+
end
|
83
|
+
|
84
|
+
def value
|
85
|
+
raw["value"]
|
86
|
+
end
|
87
|
+
|
88
|
+
def delete
|
89
|
+
@messages.delete(self.id)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/lib/iron_cache.rb
ADDED
data/test/Gemfile
ADDED
data/test/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.6)
|
5
|
+
beanstalk-client (1.1.1)
|
6
|
+
concur (0.1.2)
|
7
|
+
em-http-request
|
8
|
+
em-http-request
|
9
|
+
eventmachine
|
10
|
+
eventmachine
|
11
|
+
faraday
|
12
|
+
faraday
|
13
|
+
cookiejar (0.3.0)
|
14
|
+
em-http-request (1.0.1)
|
15
|
+
addressable (>= 2.2.3)
|
16
|
+
cookiejar
|
17
|
+
em-socksify
|
18
|
+
eventmachine (>= 1.0.0.beta.4)
|
19
|
+
http_parser.rb (>= 0.5.3)
|
20
|
+
em-socksify (0.1.0)
|
21
|
+
eventmachine
|
22
|
+
eventmachine (1.0.0.beta.4)
|
23
|
+
faraday (0.7.5)
|
24
|
+
addressable (~> 2.2.6)
|
25
|
+
multipart-post (~> 1.1.3)
|
26
|
+
rack (>= 1.1.0, < 2)
|
27
|
+
http_parser.rb (0.5.3)
|
28
|
+
multipart-post (1.1.4)
|
29
|
+
rack (1.4.0)
|
30
|
+
test-unit (2.4.4)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
beanstalk-client
|
37
|
+
concur
|
38
|
+
test-unit
|
data/test/quick_run.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Put config.yml file in ~/Dropbox/configs/ironmq_gem/test/config.yml
|
2
|
+
require_relative 'test_base'
|
3
|
+
|
4
|
+
class QuickRun < TestBase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@client.queue_name = 'ironmq-gem-quick'
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_basics
|
12
|
+
res = @client.items.post("hello world!")
|
13
|
+
assert res.id
|
14
|
+
assert res.msg
|
15
|
+
p res
|
16
|
+
|
17
|
+
res = @client.items.get()
|
18
|
+
assert res.id
|
19
|
+
assert res.body
|
20
|
+
p res
|
21
|
+
|
22
|
+
res = @client.items.delete(res["id"])
|
23
|
+
assert res.msg
|
24
|
+
p res
|
25
|
+
|
26
|
+
res = @client.items.get()
|
27
|
+
p res
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
|
data/test/test_base.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
gem 'test-unit'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'yaml'
|
4
|
+
begin
|
5
|
+
require File.join(File.dirname(__FILE__), '../lib/iron_cache')
|
6
|
+
rescue Exception => ex
|
7
|
+
puts "Could NOT load current iron_cache: " + ex.message
|
8
|
+
raise ex
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
class TestBase < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
puts 'setup'
|
15
|
+
# check multiple config locations
|
16
|
+
@config = load_config
|
17
|
+
puts "config=" + @config.inspect
|
18
|
+
@client = IronCache::Client.new(@config['iron'])
|
19
|
+
@client.logger.level = Logger::DEBUG
|
20
|
+
@client.cache_name = 'iron_cache_ruby_tests'
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def load_config
|
25
|
+
# check for config
|
26
|
+
# First check if running in abt worker
|
27
|
+
if defined? $abt_config
|
28
|
+
@config = $abt_config
|
29
|
+
return @config
|
30
|
+
end
|
31
|
+
cf = File.expand_path(File.join("~", "Dropbox", "configs", "iron_cache_ruby", "test", "config.yml"))
|
32
|
+
if File.exist?(cf)
|
33
|
+
@config = YAML::load_file(cf)
|
34
|
+
return @config
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def clear_queue(queue_name=nil)
|
41
|
+
#queue_name ||= @client.cache_name
|
42
|
+
#puts "clearing queue #{queue_name}"
|
43
|
+
#while res = @client.messages.get(:cache_name=>queue_name)
|
44
|
+
# p res
|
45
|
+
# puts res.body.to_s
|
46
|
+
# res.delete
|
47
|
+
#end
|
48
|
+
#puts 'cleared.'
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
gem 'test-unit'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'beanstalk-client'
|
4
|
+
require 'yaml'
|
5
|
+
require_relative 'test_base'
|
6
|
+
|
7
|
+
class IronCacheTests < TestBase
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_basics
|
14
|
+
@client.cache_name = 'test_basics'
|
15
|
+
clear_queue
|
16
|
+
|
17
|
+
k = "key1"
|
18
|
+
v = "hello world!"
|
19
|
+
res = @client.items.put(k, v)
|
20
|
+
# another naming option we could try:
|
21
|
+
#res = @client.cache('test_basics').items.put("key1", "hello world!")
|
22
|
+
p res
|
23
|
+
assert res.msg
|
24
|
+
|
25
|
+
res = @client.items.get(k)
|
26
|
+
p res
|
27
|
+
assert res["key"]
|
28
|
+
assert res.key
|
29
|
+
assert res.key == k
|
30
|
+
assert res.value == v
|
31
|
+
|
32
|
+
res = @client.items.delete(res.key)
|
33
|
+
p res
|
34
|
+
puts "shouldn't be any more"
|
35
|
+
res = @client.items.get(k)
|
36
|
+
p res
|
37
|
+
assert res.nil?
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_expiry
|
42
|
+
@client.cache_name = 'test_basics'
|
43
|
+
clear_queue
|
44
|
+
k = "key1"
|
45
|
+
v = "hello world!"
|
46
|
+
res = @client.items.put(k, v, :expires_in=>10)
|
47
|
+
|
48
|
+
res = @client.items.get(k)
|
49
|
+
p res
|
50
|
+
assert res.key == k
|
51
|
+
|
52
|
+
sleep 11
|
53
|
+
res = @client.items.get(k)
|
54
|
+
assert res.nil?
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
gem 'test-unit'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'beanstalk-client'
|
4
|
+
require 'yaml'
|
5
|
+
require_relative 'test_base'
|
6
|
+
|
7
|
+
class IronCacheTests < TestBase
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_basics
|
14
|
+
@client.cache_name = 'test_basics'
|
15
|
+
clear_queue
|
16
|
+
|
17
|
+
k = "key1"
|
18
|
+
v = "hello world!"
|
19
|
+
res = @client.items.put(k, v)
|
20
|
+
# another naming option we could try:
|
21
|
+
#res = @client.cache('test_basics').items.put("key1", "hello world!")
|
22
|
+
p res
|
23
|
+
assert res.msg
|
24
|
+
|
25
|
+
res = @client.items.get(k)
|
26
|
+
p res
|
27
|
+
assert res["key"]
|
28
|
+
assert res.key
|
29
|
+
assert res.key == k
|
30
|
+
assert res.value == v
|
31
|
+
|
32
|
+
res = @client.items.delete(res.key)
|
33
|
+
p res
|
34
|
+
puts "shouldn't be any more"
|
35
|
+
res = @client.items.get(k)
|
36
|
+
p res
|
37
|
+
assert res.nil?
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_expiry
|
42
|
+
@client.cache_name = 'test_basics'
|
43
|
+
clear_queue
|
44
|
+
k = "key1"
|
45
|
+
v = "hello world!"
|
46
|
+
res = @client.items.put(k, v, :expires_in=>10)
|
47
|
+
|
48
|
+
res = @client.items.get(k)
|
49
|
+
p res
|
50
|
+
assert res.key == k
|
51
|
+
|
52
|
+
sleep 11
|
53
|
+
res = @client.items.get(k)
|
54
|
+
assert res.nil?
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iron_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Travis Reeder
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-26 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: &15146280 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *15146280
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rest
|
27
|
+
requirement: &15145660 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.1.2
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *15145660
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rest-client
|
38
|
+
requirement: &15145020 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *15145020
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rest
|
49
|
+
requirement: &15144420 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.2
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *15144420
|
58
|
+
description: Ruby client for IronCache by www.iron.io
|
59
|
+
email: travis@iron.io
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files:
|
63
|
+
- README.md
|
64
|
+
files:
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- VERSION.yml
|
68
|
+
- iron_cache.gemspec
|
69
|
+
- lib/iron_cache.rb
|
70
|
+
- lib/iron_cache/caches.rb
|
71
|
+
- lib/iron_cache/client.rb
|
72
|
+
- lib/iron_cache/items.rb
|
73
|
+
- test/Gemfile
|
74
|
+
- test/Gemfile.lock
|
75
|
+
- test/quick_run.rb
|
76
|
+
- test/test_base.rb
|
77
|
+
- test/test_iron_cache.rb
|
78
|
+
- test/test_memcached.rb
|
79
|
+
homepage: http://www.iron.io
|
80
|
+
licenses: []
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.9'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.15
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Ruby client for IronCache by www.iron.io
|
103
|
+
test_files: []
|