kyototycoon 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +1 -12
- data/Gemfile.lock +14 -6
- data/kyototycoon.gemspec +12 -41
- data/lib/kyototycoon.rb +19 -6
- data/spec/connect_spec.rb +72 -0
- data/spec/options_spec.rb +132 -0
- data/spec/spec_helper.rb +37 -0
- metadata +66 -64
- data/spec/helper.rb +0 -194
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
coverage/
|
data/Gemfile
CHANGED
@@ -1,14 +1,3 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
2
|
|
6
|
-
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
|
-
group :development do
|
9
|
-
gem "rspec", "~> 2.1.0"
|
10
|
-
gem "bundler", "~> 1.0.0"
|
11
|
-
gem "jeweler", "~> 1.5.1"
|
12
|
-
gem "rcov", ">= 0"
|
13
|
-
gem "msgpack", ">= 0"
|
14
|
-
end
|
3
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kyototycoon (0.5.5)
|
5
|
+
msgpack
|
6
|
+
|
1
7
|
GEM
|
2
8
|
remote: http://rubygems.org/
|
3
9
|
specs:
|
4
10
|
diff-lcs (1.1.2)
|
5
11
|
git (1.2.5)
|
6
|
-
jeweler (1.5.
|
12
|
+
jeweler (1.5.2)
|
7
13
|
bundler (~> 1.0.0)
|
8
14
|
git (>= 1.2.5)
|
9
15
|
rake
|
10
|
-
msgpack (0.4.
|
11
|
-
rake (0.
|
12
|
-
rcov (0.9.9)
|
16
|
+
msgpack (0.4.5)
|
17
|
+
rake (0.9.2)
|
13
18
|
rspec (2.1.0)
|
14
19
|
rspec-core (~> 2.1.0)
|
15
20
|
rspec-expectations (~> 2.1.0)
|
@@ -18,6 +23,9 @@ GEM
|
|
18
23
|
rspec-expectations (2.1.0)
|
19
24
|
diff-lcs (~> 1.1.2)
|
20
25
|
rspec-mocks (2.1.0)
|
26
|
+
simplecov (0.4.2)
|
27
|
+
simplecov-html (~> 0.4.4)
|
28
|
+
simplecov-html (0.4.5)
|
21
29
|
|
22
30
|
PLATFORMS
|
23
31
|
ruby
|
@@ -25,6 +33,6 @@ PLATFORMS
|
|
25
33
|
DEPENDENCIES
|
26
34
|
bundler (~> 1.0.0)
|
27
35
|
jeweler (~> 1.5.1)
|
28
|
-
|
29
|
-
rcov
|
36
|
+
kyototycoon!
|
30
37
|
rspec (~> 2.1.0)
|
38
|
+
simplecov
|
data/kyototycoon.gemspec
CHANGED
@@ -1,78 +1,49 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
5
3
|
|
6
4
|
Gem::Specification.new do |s|
|
7
5
|
s.name = %q{kyototycoon}
|
8
|
-
s.version = "0.5.
|
6
|
+
s.version = "0.5.5"
|
9
7
|
|
10
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
9
|
s.authors = ["uu59"]
|
12
|
-
s.date = %q{2011-
|
10
|
+
s.date = %q{2011-07-30}
|
13
11
|
s.default_executable = %q{kyototycoon-console}
|
14
12
|
s.description = %q{KyotoTycoon client for Ruby}
|
15
13
|
s.email = %q{k@uu59.org}
|
16
|
-
s.executables = ["kyototycoon-console"]
|
17
14
|
s.extra_rdoc_files = [
|
18
15
|
"README.markdown"
|
19
16
|
]
|
20
|
-
s.files
|
21
|
-
"
|
22
|
-
|
23
|
-
"Gemfile.lock",
|
24
|
-
"MIT-LICENSE",
|
25
|
-
"README.markdown",
|
26
|
-
"Rakefile",
|
27
|
-
"VERSION",
|
28
|
-
"benchmark/bulk.rb",
|
29
|
-
"benchmark/bulk_bigdata.rb",
|
30
|
-
"benchmark/getset.rb",
|
31
|
-
"benchmark/getset_while_1sec.rb",
|
32
|
-
"benchmark/helper.rb",
|
33
|
-
"bin/kyototycoon-console",
|
34
|
-
"kyototycoon.gemspec",
|
35
|
-
"lib/kyototycoon.rb",
|
36
|
-
"lib/kyototycoon/serializer.rb",
|
37
|
-
"lib/kyototycoon/serializer/default.rb",
|
38
|
-
"lib/kyototycoon/serializer/msgpack.rb",
|
39
|
-
"lib/kyototycoon/stream.rb",
|
40
|
-
"lib/kyototycoon/tsvrpc.rb",
|
41
|
-
"lib/kyototycoon/tsvrpc/skinny.rb",
|
42
|
-
"spec/helper.rb",
|
43
|
-
"spec/ktslave.txt"
|
44
|
-
]
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
45
20
|
s.homepage = %q{http://github.com/uu59/kyototycoon-ruby}
|
46
21
|
s.licenses = ["MIT"]
|
47
22
|
s.require_paths = ["lib"]
|
48
23
|
s.rubygems_version = %q{1.6.2}
|
49
24
|
s.summary = %q{KyotoTycoon client for Ruby}
|
50
|
-
|
51
|
-
|
52
|
-
]
|
25
|
+
|
26
|
+
s.add_dependency(%q<msgpack>, [">= 0"])
|
53
27
|
|
54
28
|
if s.respond_to? :specification_version then
|
55
29
|
s.specification_version = 3
|
56
|
-
|
30
|
+
|
57
31
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
32
|
s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
|
59
33
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
34
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
61
|
-
s.add_development_dependency(%q<
|
62
|
-
s.add_development_dependency(%q<msgpack>, [">= 0"])
|
35
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
63
36
|
else
|
64
37
|
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
65
38
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
66
39
|
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
67
|
-
s.add_dependency(%q<
|
68
|
-
s.add_dependency(%q<msgpack>, [">= 0"])
|
40
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
69
41
|
end
|
70
42
|
else
|
71
43
|
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
72
44
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
73
45
|
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
74
|
-
s.add_dependency(%q<
|
75
|
-
s.add_dependency(%q<msgpack>, [">= 0"])
|
46
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
76
47
|
end
|
77
48
|
end
|
78
49
|
|
data/lib/kyototycoon.rb
CHANGED
@@ -4,7 +4,7 @@ require "logger"
|
|
4
4
|
require "cgi"
|
5
5
|
require "socket"
|
6
6
|
require "base64"
|
7
|
-
require "
|
7
|
+
require "timeout"
|
8
8
|
require "kyototycoon/serializer.rb"
|
9
9
|
require "kyototycoon/serializer/default.rb"
|
10
10
|
require "kyototycoon/serializer/msgpack.rb"
|
@@ -13,7 +13,7 @@ require "kyototycoon/tsvrpc/skinny.rb"
|
|
13
13
|
require "kyototycoon/stream.rb"
|
14
14
|
|
15
15
|
class KyotoTycoon
|
16
|
-
VERSION = '0.5.
|
16
|
+
VERSION = '0.5.5'
|
17
17
|
|
18
18
|
attr_accessor :colenc, :connect_timeout, :servers
|
19
19
|
attr_reader :serializer, :logger, :db
|
@@ -32,6 +32,14 @@ class KyotoTycoon
|
|
32
32
|
kt
|
33
33
|
}
|
34
34
|
end
|
35
|
+
|
36
|
+
def self.configures
|
37
|
+
@configure
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.configure_reset!
|
41
|
+
@configure = {}
|
42
|
+
end
|
35
43
|
|
36
44
|
def self.create(name)
|
37
45
|
if @configure[name].nil?
|
@@ -126,7 +134,7 @@ class KyotoTycoon
|
|
126
134
|
# records={'a' => 'aa', 'b' => 'bb'}
|
127
135
|
values = {}
|
128
136
|
records.each{|k,v|
|
129
|
-
values["_#{k}"] = @serializer.encode(v)
|
137
|
+
values[k.to_s.match(/^_/) ? k.to_s : "_#{k}"] = @serializer.encode(v)
|
130
138
|
}
|
131
139
|
res = request('/rpc/set_bulk', values)
|
132
140
|
Tsvrpc.parse(res[:body], res[:colenc])
|
@@ -139,9 +147,13 @@ class KyotoTycoon
|
|
139
147
|
}
|
140
148
|
res = request('/rpc/get_bulk', params)
|
141
149
|
ret = {}
|
142
|
-
Tsvrpc.parse(res[:body], res[:colenc])
|
143
|
-
|
144
|
-
}
|
150
|
+
bulk = Tsvrpc.parse(res[:body], res[:colenc])
|
151
|
+
bulk.keep_if {|k,v| k.match(/^_/)}
|
152
|
+
ret = bulk.reduce({}) do |hash, (k,v)|
|
153
|
+
key = k.match(/^_/) ? k[1..-1] : k
|
154
|
+
hash[key] = @serializer.decode(v)
|
155
|
+
hash
|
156
|
+
end
|
145
157
|
ret
|
146
158
|
end
|
147
159
|
|
@@ -263,6 +275,7 @@ class KyotoTycoon
|
|
263
275
|
@logger.warn("connect failed at #{host}:#{port}")
|
264
276
|
false
|
265
277
|
ensure
|
278
|
+
# for 1.8.7
|
266
279
|
rpc.finish
|
267
280
|
end
|
268
281
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# -- coding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
|
5
|
+
|
6
|
+
describe KyotoTycoon do
|
7
|
+
it 'should handle multi servers' do
|
8
|
+
kt = KyotoTycoon.new('www.example.com', 11111)
|
9
|
+
kt.connect_timeout = 0.1
|
10
|
+
kt.servers << ['example.net', 1978]
|
11
|
+
kt.servers << ['0.0.0.0', 19999]
|
12
|
+
kt['foo'] = 'bar'
|
13
|
+
kt[:foo].should == 'bar'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should configure/create method works' do
|
17
|
+
logger = Logger.new(STDOUT)
|
18
|
+
KyotoTycoon.configure(:test) do |kt|
|
19
|
+
kt.logger = logger
|
20
|
+
kt.serializer = :msgpack
|
21
|
+
kt.db = 'foobar'
|
22
|
+
end
|
23
|
+
KyotoTycoon.configure(:test2, 'host', 1999) do |kt|
|
24
|
+
kt.logger = logger
|
25
|
+
kt.serializer = :msgpack
|
26
|
+
kt.db = 'foobar'
|
27
|
+
end
|
28
|
+
%w!test test2!.each{|name|
|
29
|
+
kt = KyotoTycoon.create(name.to_sym)
|
30
|
+
kt.logger.should == logger
|
31
|
+
kt.serializer.should == KyotoTycoon::Serializer::Msgpack
|
32
|
+
kt.db.should == 'foobar'
|
33
|
+
}
|
34
|
+
lambda { KyotoTycoon.configure(:test2) }.should raise_error(StandardError)
|
35
|
+
lambda { KyotoTycoon.create(:not_exists) }.should raise_error(StandardError)
|
36
|
+
|
37
|
+
KyotoTycoon.configures.length.should == 2
|
38
|
+
KyotoTycoon.configure_reset!
|
39
|
+
KyotoTycoon.configures.length.should == 0
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should handle `ktremotemgr slave`' do
|
43
|
+
io = File.open("#{File.dirname(__FILE__)}/ktslave.txt", "r")
|
44
|
+
current = 0
|
45
|
+
KyotoTycoon::Stream.run(io){|line|
|
46
|
+
case current
|
47
|
+
when 0 # clear command
|
48
|
+
line.cmd.should == 'clear'
|
49
|
+
line.xt_time.should == Time.at(0)
|
50
|
+
line.value.should be_nil
|
51
|
+
line.key.should be_nil
|
52
|
+
line.value.should be_nil
|
53
|
+
when 1 # set foo bar
|
54
|
+
line.cmd.should == 'set'
|
55
|
+
line.xt_time.should > Time.now
|
56
|
+
line.key.should == 'foo'
|
57
|
+
line.value.should == 'bar'
|
58
|
+
when 2 # set fooxt bar with xt(2010-12-23 22:09:49 +0900)
|
59
|
+
line.cmd.should == 'set'
|
60
|
+
line.key.should == 'fooxt'
|
61
|
+
line.value.should == 'bar'
|
62
|
+
line.xt_time.should > Time.at(1234567890)
|
63
|
+
line.xt_time.should < Time.at(1334567890)
|
64
|
+
when 3 # remove foo
|
65
|
+
line.cmd.should == 'remove'
|
66
|
+
line.key.should == 'foo'
|
67
|
+
line.value.should be_nil
|
68
|
+
end
|
69
|
+
current += 1
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# -- coding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
|
4
|
+
|
5
|
+
describe KyotoTycoon do
|
6
|
+
[:U, :B].each{|colenc|
|
7
|
+
context "colenc=#{colenc}" do
|
8
|
+
before(:each) do
|
9
|
+
@kt.colenc = colenc
|
10
|
+
end
|
11
|
+
|
12
|
+
[:default, :msgpack].each{|serializer|
|
13
|
+
context "serializer=#{serializer}" do
|
14
|
+
before(:each) do
|
15
|
+
@kt.serializer = serializer
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should provide simple kvs feature' do
|
19
|
+
@kt.set('a', 'b')
|
20
|
+
@kt.get('a').should == 'b'
|
21
|
+
@kt['foo'] = 'bar'
|
22
|
+
@kt['foo'].should == 'bar'
|
23
|
+
@kt.delete('foo')
|
24
|
+
@kt['foo'].should be_nil
|
25
|
+
|
26
|
+
@kt.add('123', '123')
|
27
|
+
@kt['123'].should == '123'
|
28
|
+
@kt.replace('123', '456')
|
29
|
+
@kt['123'].should == '456'
|
30
|
+
@kt.clear
|
31
|
+
@kt.report['db_total_count'].to_i.should == 0
|
32
|
+
@kt.status['count'].to_i.should == 0
|
33
|
+
|
34
|
+
@kt['foo'] = 'oldbaz'
|
35
|
+
@kt.cas('foo', 'oldbaz', 'newbaz').should be_true
|
36
|
+
@kt.cas('foo', 'oldbaz', 'newbaz').should be_false
|
37
|
+
@kt.get('foo').should == 'newbaz'
|
38
|
+
@kt.clear
|
39
|
+
|
40
|
+
@kt['foo'] ||= 'aaa'
|
41
|
+
@kt['foo'] ||= 'bbb'
|
42
|
+
@kt['foo'].should == 'aaa'
|
43
|
+
@kt.clear
|
44
|
+
|
45
|
+
@kt[:a] = 1
|
46
|
+
@kt[:b] = 1
|
47
|
+
@kt.keys.sort.should == %w!a b!.sort
|
48
|
+
@kt.clear
|
49
|
+
|
50
|
+
@kt[:longvalue] = "-" * 2048
|
51
|
+
@kt[:longvalue].should == '-' * 2048
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should provide bulk' do
|
55
|
+
data = {}
|
56
|
+
10.times{|n|
|
57
|
+
data[n.to_s] = n.to_s
|
58
|
+
}
|
59
|
+
@kt.set_bulk(data)
|
60
|
+
@kt.get_bulk(data.keys).sort.should == data.sort
|
61
|
+
@kt.remove_bulk(data.keys)
|
62
|
+
@kt.get_bulk(data.keys).should == {}
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should can handle strange key/value' do
|
66
|
+
# '+' is known ambiguity key on URL encode/decode processing
|
67
|
+
%w!a\tb a\nb a\r\nb a*-b a^@b!.each{|outlaw|
|
68
|
+
@kt[outlaw] = outlaw
|
69
|
+
@kt[outlaw].should == outlaw
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should provide delete variation' do
|
74
|
+
build = lambda {|kt|
|
75
|
+
kt.clear
|
76
|
+
kt.set_bulk({
|
77
|
+
:a => 1,
|
78
|
+
:b => 1,
|
79
|
+
:c => 1,
|
80
|
+
})
|
81
|
+
}
|
82
|
+
build.call(@kt)
|
83
|
+
@kt.delete('a','b')
|
84
|
+
@kt.keys.should == ['c']
|
85
|
+
|
86
|
+
build.call(@kt)
|
87
|
+
@kt.delete(['a', 'b'])
|
88
|
+
@kt.keys.should == ['c']
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should increment' do
|
92
|
+
@kt.increment('foo').should == 1
|
93
|
+
@kt.increment('foo').should == 2
|
94
|
+
@kt.increment('foo').should == 3
|
95
|
+
@kt.increment('foo', 10).should == 13
|
96
|
+
@kt.increment('foo', -10).should == 3
|
97
|
+
@kt.decrement('foo', 5).should == -2
|
98
|
+
@kt.incr('foo', 5).should == 3
|
99
|
+
@kt.decr('foo', 5).should == -2
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should provide status/report' do
|
103
|
+
@kt[:a] = 1
|
104
|
+
@kt[:b] = 2
|
105
|
+
@kt.report['db_total_count'].to_i.should == 2
|
106
|
+
@kt.status['count'].to_i.should == 2
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should match prefixes' do
|
110
|
+
@kt['123'] = 1
|
111
|
+
@kt['124'] = 1
|
112
|
+
@kt['125'] = 1
|
113
|
+
@kt['999'] = 1
|
114
|
+
@kt['9999'] = 1
|
115
|
+
@kt.match_prefix("12").sort.should == %w!123 124 125!.sort
|
116
|
+
@kt.match_prefix("9").sort.should == %w!999 9999!.sort
|
117
|
+
@kt.match_prefix("9999").sort.should == %w!9999!
|
118
|
+
@kt.match_regex(/^12/).sort.should == %w!123 124 125!.sort
|
119
|
+
@kt.match_regex(/^9+$/).sort.should == %w!999 9999!.sort
|
120
|
+
end
|
121
|
+
|
122
|
+
if serializer == :msgpack
|
123
|
+
it 'should keep variable type(int) with msgpack' do
|
124
|
+
@kt["foo"] = 42
|
125
|
+
@kt["foo"].should == 42
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
}
|
130
|
+
end
|
131
|
+
}
|
132
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# -- coding: utf-8
|
2
|
+
|
3
|
+
=begin
|
4
|
+
|
5
|
+
!!!!!!!!!!!!!
|
6
|
+
!! CAUTION !!
|
7
|
+
!!!!!!!!!!!!!
|
8
|
+
|
9
|
+
This script access http://0.0.0.0:19999/ and destroy all records.
|
10
|
+
Be carefully for run, and run `ktserver -port 19999 '*'` before testing.
|
11
|
+
|
12
|
+
=end
|
13
|
+
|
14
|
+
unless ENV["COV"].nil?
|
15
|
+
require "simplecov"
|
16
|
+
SimpleCov.start
|
17
|
+
end
|
18
|
+
|
19
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../lib")
|
20
|
+
require "rubygems"
|
21
|
+
require "kyototycoon.rb"
|
22
|
+
require "kyototycoon/stream.rb"
|
23
|
+
|
24
|
+
RSpec.configure do |conf|
|
25
|
+
conf.before(:all) do
|
26
|
+
@kt = KyotoTycoon.new('0.0.0.0', 19999)
|
27
|
+
@kt.serializer=:default # or :msgpack
|
28
|
+
@kt.logger=nil
|
29
|
+
end
|
30
|
+
|
31
|
+
conf.before(:each) do
|
32
|
+
end
|
33
|
+
|
34
|
+
conf.after(:each) do
|
35
|
+
@kt.clear
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,82 +1,81 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: kyototycoon
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.5
|
4
5
|
prerelease:
|
5
|
-
version: 0.5.4
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- uu59
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-06-29 00:00:00 +10:00
|
12
|
+
date: 2011-07-30 00:00:00.000000000 +10:00
|
14
13
|
default_executable: kyototycoon-console
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: msgpack
|
17
|
+
requirement: &2153386360 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
18
24
|
prerelease: false
|
19
|
-
|
25
|
+
version_requirements: *2153386360
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: &2153384620 !ruby/object:Gem::Requirement
|
20
29
|
none: false
|
21
|
-
requirements:
|
30
|
+
requirements:
|
22
31
|
- - ~>
|
23
|
-
- !ruby/object:Gem::Version
|
32
|
+
- !ruby/object:Gem::Version
|
24
33
|
version: 2.1.0
|
25
34
|
type: :development
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
35
|
prerelease: false
|
30
|
-
|
36
|
+
version_requirements: *2153384620
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
requirement: &2153384020 !ruby/object:Gem::Requirement
|
31
40
|
none: false
|
32
|
-
requirements:
|
41
|
+
requirements:
|
33
42
|
- - ~>
|
34
|
-
- !ruby/object:Gem::Version
|
43
|
+
- !ruby/object:Gem::Version
|
35
44
|
version: 1.0.0
|
36
45
|
type: :development
|
37
|
-
version_requirements: *id002
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: jeweler
|
40
46
|
prerelease: false
|
41
|
-
|
47
|
+
version_requirements: *2153384020
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: jeweler
|
50
|
+
requirement: &2153383420 !ruby/object:Gem::Requirement
|
42
51
|
none: false
|
43
|
-
requirements:
|
52
|
+
requirements:
|
44
53
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
54
|
+
- !ruby/object:Gem::Version
|
46
55
|
version: 1.5.1
|
47
56
|
type: :development
|
48
|
-
version_requirements: *id003
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: rcov
|
51
57
|
prerelease: false
|
52
|
-
|
58
|
+
version_requirements: *2153383420
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: simplecov
|
61
|
+
requirement: &2153382800 !ruby/object:Gem::Requirement
|
53
62
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
58
67
|
type: :development
|
59
|
-
version_requirements: *id004
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: msgpack
|
62
68
|
prerelease: false
|
63
|
-
|
64
|
-
none: false
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: "0"
|
69
|
-
type: :development
|
70
|
-
version_requirements: *id005
|
69
|
+
version_requirements: *2153382800
|
71
70
|
description: KyotoTycoon client for Ruby
|
72
71
|
email: k@uu59.org
|
73
|
-
executables:
|
72
|
+
executables:
|
74
73
|
- kyototycoon-console
|
75
74
|
extensions: []
|
76
|
-
|
77
|
-
extra_rdoc_files:
|
75
|
+
extra_rdoc_files:
|
78
76
|
- README.markdown
|
79
|
-
files:
|
77
|
+
files:
|
78
|
+
- .gitignore
|
80
79
|
- Changes.md
|
81
80
|
- Gemfile
|
82
81
|
- Gemfile.lock
|
@@ -98,35 +97,38 @@ files:
|
|
98
97
|
- lib/kyototycoon/stream.rb
|
99
98
|
- lib/kyototycoon/tsvrpc.rb
|
100
99
|
- lib/kyototycoon/tsvrpc/skinny.rb
|
101
|
-
- spec/
|
100
|
+
- spec/connect_spec.rb
|
102
101
|
- spec/ktslave.txt
|
102
|
+
- spec/options_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
103
104
|
has_rdoc: true
|
104
105
|
homepage: http://github.com/uu59/kyototycoon-ruby
|
105
|
-
licenses:
|
106
|
+
licenses:
|
106
107
|
- MIT
|
107
108
|
post_install_message:
|
108
109
|
rdoc_options: []
|
109
|
-
|
110
|
-
require_paths:
|
110
|
+
require_paths:
|
111
111
|
- lib
|
112
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
|
-
requirements:
|
115
|
-
- -
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version:
|
118
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
119
|
none: false
|
120
|
-
requirements:
|
121
|
-
- -
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version:
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
124
|
requirements: []
|
125
|
-
|
126
125
|
rubyforge_project:
|
127
126
|
rubygems_version: 1.6.2
|
128
127
|
signing_key:
|
129
128
|
specification_version: 3
|
130
129
|
summary: KyotoTycoon client for Ruby
|
131
|
-
test_files:
|
132
|
-
- spec/
|
130
|
+
test_files:
|
131
|
+
- spec/connect_spec.rb
|
132
|
+
- spec/ktslave.txt
|
133
|
+
- spec/options_spec.rb
|
134
|
+
- spec/spec_helper.rb
|
data/spec/helper.rb
DELETED
@@ -1,194 +0,0 @@
|
|
1
|
-
# -- coding: utf-8
|
2
|
-
|
3
|
-
=begin
|
4
|
-
|
5
|
-
!!!!!!!!!!!!!
|
6
|
-
!! CAUTION !!
|
7
|
-
!!!!!!!!!!!!!
|
8
|
-
|
9
|
-
This script access http://0.0.0.0:19999/ and destroy all records.
|
10
|
-
Be carefully for run, and run `ktserver -port 19999 '*'` before testing.
|
11
|
-
|
12
|
-
=end
|
13
|
-
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../lib")
|
15
|
-
require "rubygems"
|
16
|
-
require "kyototycoon.rb"
|
17
|
-
require "kyototycoon/stream.rb"
|
18
|
-
|
19
|
-
describe do
|
20
|
-
before(:all) do
|
21
|
-
@kt = KyotoTycoon.new('0.0.0.0', 19999)
|
22
|
-
@kt.serializer=:default # or :msgpack
|
23
|
-
@kt.logger=nil
|
24
|
-
end
|
25
|
-
|
26
|
-
before(:each) do
|
27
|
-
end
|
28
|
-
|
29
|
-
after(:each) do
|
30
|
-
@kt.clear
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should handle multi servers' do
|
34
|
-
kt = KyotoTycoon.new('www.example.com', 11111)
|
35
|
-
kt.connect_timeout = 0.1
|
36
|
-
kt.servers << ['example.net', 1978]
|
37
|
-
kt.servers << ['0.0.0.0', 19999]
|
38
|
-
kt['foo'] = 'bar'
|
39
|
-
kt[:foo].should == 'bar'
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should provide simple kvs feature' do
|
43
|
-
@kt.set('a', 'b')
|
44
|
-
@kt.get('a').should == 'b'
|
45
|
-
@kt['foo'] = 'bar'
|
46
|
-
@kt['foo'].should == 'bar'
|
47
|
-
@kt.delete('foo')
|
48
|
-
@kt['foo'].should be_nil
|
49
|
-
@kt.clear
|
50
|
-
@kt.report['db_total_count'].to_i.should == 0
|
51
|
-
@kt.status['count'].to_i.should == 0
|
52
|
-
|
53
|
-
@kt['foo'] = 'oldbaz'
|
54
|
-
@kt.cas('foo', 'oldbaz', 'newbaz').should be_true
|
55
|
-
@kt.cas('foo', 'oldbaz', 'newbaz').should be_false
|
56
|
-
@kt.get('foo').should == 'newbaz'
|
57
|
-
@kt.clear
|
58
|
-
|
59
|
-
@kt['foo'] ||= 'aaa'
|
60
|
-
@kt['foo'] ||= 'bbb'
|
61
|
-
@kt['foo'].should == 'aaa'
|
62
|
-
@kt.clear
|
63
|
-
|
64
|
-
@kt[:a] = 1
|
65
|
-
@kt[:b] = 1
|
66
|
-
@kt.keys.sort.should == %w!a b!.sort
|
67
|
-
@kt.clear
|
68
|
-
|
69
|
-
@kt[:longvalue] = "-" * 2048
|
70
|
-
@kt[:longvalue].should == '-' * 2048
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should provide bulk' do
|
74
|
-
data = {}
|
75
|
-
receive = {}
|
76
|
-
10.times{|n|
|
77
|
-
data[n.to_s] = n.to_s
|
78
|
-
receive["_#{n}"] = n.to_s
|
79
|
-
}
|
80
|
-
receive['num'] = "10"
|
81
|
-
@kt.set_bulk(data)
|
82
|
-
@kt.get_bulk(data.keys).sort.should == receive.sort
|
83
|
-
@kt.remove_bulk(data.keys)
|
84
|
-
@kt.get_bulk(data.keys).should == {'num' => '0'}
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'should can handle strange key/value' do
|
88
|
-
# '+' is known ambiguity key on URL encode/decode processing
|
89
|
-
%w!a\tb a\nb a\r\nb a*-b a^@b!.each{|outlaw|
|
90
|
-
@kt[outlaw] = outlaw
|
91
|
-
@kt[outlaw].should == outlaw
|
92
|
-
}
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'should provide delete variation' do
|
96
|
-
build = lambda {|kt|
|
97
|
-
kt.clear
|
98
|
-
kt.set_bulk({
|
99
|
-
:a => 1,
|
100
|
-
:b => 1,
|
101
|
-
:c => 1,
|
102
|
-
})
|
103
|
-
}
|
104
|
-
build.call(@kt)
|
105
|
-
@kt.delete('a','b')
|
106
|
-
@kt.keys.should == ['c']
|
107
|
-
|
108
|
-
build.call(@kt)
|
109
|
-
@kt.delete(['a', 'b'])
|
110
|
-
@kt.keys.should == ['c']
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'should increment' do
|
114
|
-
@kt.increment('foo').should == 1
|
115
|
-
@kt.increment('foo').should == 2
|
116
|
-
@kt.increment('foo').should == 3
|
117
|
-
@kt.increment('foo', 10).should == 13
|
118
|
-
@kt.increment('foo', -10).should == 3
|
119
|
-
@kt.decrement('foo', 5).should == -2
|
120
|
-
@kt.incr('foo', 5).should == 3
|
121
|
-
@kt.decr('foo', 5).should == -2
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should provide status/report' do
|
125
|
-
@kt[:a] = 1
|
126
|
-
@kt[:b] = 2
|
127
|
-
@kt.report['db_total_count'].to_i.should == 2
|
128
|
-
@kt.status['count'].to_i.should == 2
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'should match prefixes' do
|
132
|
-
@kt['123'] = 1
|
133
|
-
@kt['124'] = 1
|
134
|
-
@kt['125'] = 1
|
135
|
-
@kt['999'] = 1
|
136
|
-
@kt['9999'] = 1
|
137
|
-
@kt.match_prefix("12").sort.should == %w!123 124 125!.sort
|
138
|
-
@kt.match_prefix("9").sort.should == %w!999 9999!.sort
|
139
|
-
@kt.match_prefix("9999").sort.should == %w!9999!
|
140
|
-
@kt.match_regex(/^12/).sort.should == %w!123 124 125!.sort
|
141
|
-
@kt.match_regex(/^9+$/).sort.should == %w!999 9999!.sort
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'should configure/create method works' do
|
145
|
-
logger = Logger.new(STDOUT)
|
146
|
-
KyotoTycoon.configure(:test) do |kt|
|
147
|
-
kt.logger = logger
|
148
|
-
kt.serializer = :msgpack
|
149
|
-
kt.db = 'foobar'
|
150
|
-
end
|
151
|
-
KyotoTycoon.configure(:test2, 'host', 1999) do |kt|
|
152
|
-
kt.logger = logger
|
153
|
-
kt.serializer = :msgpack
|
154
|
-
kt.db = 'foobar'
|
155
|
-
end
|
156
|
-
%w!test test2!.each{|name|
|
157
|
-
kt = KyotoTycoon.create(name.to_sym)
|
158
|
-
kt.logger.should == logger
|
159
|
-
kt.serializer.should == KyotoTycoon::Serializer::Msgpack
|
160
|
-
kt.db.should == 'foobar'
|
161
|
-
}
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'should handle `ktremotemgr slave`' do
|
165
|
-
io = File.open("#{File.dirname(__FILE__)}/ktslave.txt", "r")
|
166
|
-
current = 0
|
167
|
-
KyotoTycoon::Stream.run(io){|line|
|
168
|
-
case current
|
169
|
-
when 0 # clear command
|
170
|
-
line.cmd.should == 'clear'
|
171
|
-
line.xt_time.should == Time.at(0)
|
172
|
-
line.value.should be_nil
|
173
|
-
line.key.should be_nil
|
174
|
-
line.value.should be_nil
|
175
|
-
when 1 # set foo bar
|
176
|
-
line.cmd.should == 'set'
|
177
|
-
line.xt_time.should > Time.now
|
178
|
-
line.key.should == 'foo'
|
179
|
-
line.value.should == 'bar'
|
180
|
-
when 2 # set fooxt bar with xt(2010-12-23 22:09:49 +0900)
|
181
|
-
line.cmd.should == 'set'
|
182
|
-
line.key.should == 'fooxt'
|
183
|
-
line.value.should == 'bar'
|
184
|
-
line.xt_time.should > Time.at(1234567890)
|
185
|
-
line.xt_time.should < Time.at(1334567890)
|
186
|
-
when 3 # remove foo
|
187
|
-
line.cmd.should == 'remove'
|
188
|
-
line.key.should == 'foo'
|
189
|
-
line.value.should be_nil
|
190
|
-
end
|
191
|
-
current += 1
|
192
|
-
}
|
193
|
-
end
|
194
|
-
end
|