kyototycoon-client 0.0.3 → 0.0.4
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.
@@ -29,9 +29,11 @@ module Kyototycoon
|
|
29
29
|
header_entries = [Magic::SET_BULK, Flag::RESERVED, records.length]
|
30
30
|
request = header_entries.pack("CNN")
|
31
31
|
|
32
|
-
records.each do |r|
|
33
|
-
|
34
|
-
|
32
|
+
records.each do |r|
|
33
|
+
k = r.key.dup.force_encoding("binary")
|
34
|
+
v = r.value.force_encoding("binary")
|
35
|
+
request << [r.db_id, k.length, v.length, r.expire.to_i >> 32,
|
36
|
+
r.expire.to_i & 0x00000000FFFFFFFF].pack("nN*") << k << v
|
35
37
|
end
|
36
38
|
|
37
39
|
@socket.write(request)
|
@@ -49,7 +51,8 @@ module Kyototycoon
|
|
49
51
|
request = header_entries.pack("CNN")
|
50
52
|
|
51
53
|
records.each do |r|
|
52
|
-
|
54
|
+
k = r.key.dup.force_encoding('binary')
|
55
|
+
request << [r.db_id, k.length].pack("nN") << k
|
53
56
|
end
|
54
57
|
|
55
58
|
@socket.write(request)
|
@@ -63,14 +66,13 @@ module Kyototycoon
|
|
63
66
|
count.times do |i|
|
64
67
|
res_body = @socket.read(18)
|
65
68
|
|
66
|
-
dbid, keysize, valuesize, ext_expire, expire = res_body.unpack("
|
69
|
+
dbid, keysize, valuesize, ext_expire, expire = res_body.unpack("nN*")
|
67
70
|
expire = ext_expire << 32 | expire
|
68
71
|
|
69
72
|
key = @socket.read(keysize)
|
70
73
|
value = @socket.read(valuesize)
|
71
|
-
results.push(Record.new(key, value,
|
74
|
+
results.push(Record.new(key.dup.force_encoding('UTF-8'), value.force_encoding('UTF-8'), expire, dbid))
|
72
75
|
end
|
73
|
-
|
74
76
|
results
|
75
77
|
end
|
76
78
|
|
@@ -79,7 +81,8 @@ module Kyototycoon
|
|
79
81
|
request = header_entries.pack("CNN")
|
80
82
|
|
81
83
|
records.each do |r|
|
82
|
-
|
84
|
+
k = r.key.dup.force_encoding('binary')
|
85
|
+
request << [r.db_id, k.length].pack("nN") << k
|
83
86
|
end
|
84
87
|
|
85
88
|
@socket.write(request)
|
@@ -97,7 +100,9 @@ module Kyototycoon
|
|
97
100
|
request = header_entries.pack("CNN")
|
98
101
|
|
99
102
|
records.each do |r|
|
100
|
-
|
103
|
+
k = r.key.dup.force_encoding("binary")
|
104
|
+
v = r.value.force_encoding("binary")
|
105
|
+
request << [k.length, v.length].pack("NN") << k << v
|
101
106
|
end
|
102
107
|
|
103
108
|
@socket.write(request)
|
@@ -113,7 +118,7 @@ module Kyototycoon
|
|
113
118
|
keysize, valuesize = res_body.unpack("NN")
|
114
119
|
key = @socket.read(keysize)
|
115
120
|
value = @socket.read(valuesize)
|
116
|
-
results.push(Record.new(key, value, 0, 0))
|
121
|
+
results.push(Record.new(key.dup.force_encoding('UTF-8'), value.force_encoding('UTF-8'), 0, 0))
|
117
122
|
end
|
118
123
|
|
119
124
|
results
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require "helper"
|
2
3
|
|
3
4
|
class ClientTest < Test::Unit::TestCase
|
@@ -26,6 +27,16 @@ class ClientTest < Test::Unit::TestCase
|
|
26
27
|
@client.close
|
27
28
|
end
|
28
29
|
|
30
|
+
def test_clud_multibyte_characters
|
31
|
+
@client.open
|
32
|
+
assert_equal(@client.set("あ", "あいのまち"), true)
|
33
|
+
assert_equal(@client.get("あ"), "あいのまち")
|
34
|
+
assert_nil(@client.get("ん"))
|
35
|
+
assert_equal(@client.remove("あ"), true)
|
36
|
+
assert_nil(@client.get("あ"))
|
37
|
+
@client.close
|
38
|
+
end
|
39
|
+
|
29
40
|
def test_clud_bulk
|
30
41
|
@client.open
|
31
42
|
@client.remove_bulk(["key1", "key2", "key3", "key4"])
|
@@ -39,6 +50,19 @@ class ClientTest < Test::Unit::TestCase
|
|
39
50
|
@client.close
|
40
51
|
end
|
41
52
|
|
53
|
+
def test_clud_bulk_multibyte_charactors
|
54
|
+
@client.open
|
55
|
+
@client.remove_bulk(["あ", "い", "う", "え"])
|
56
|
+
|
57
|
+
assert_equal( @client.set_bulk( {"あ" => "あいのまち", "い" => "いしかずちょう", "う" => "ういろうのちょう"} ), 3)
|
58
|
+
assert_equal( @client.get_bulk( ["あ", "い", "う", "え"] ),
|
59
|
+
{"あ" => "あいのまち", "い" => "いしかずちょう", "う" => "ういろうのちょう"} )
|
60
|
+
assert_equal( @client.remove_bulk( ["あ", "い"] ), 2 )
|
61
|
+
assert_equal( @client.get_bulk( ["あ", "い", "う", "え"] ),
|
62
|
+
{"う" => "ういろうのちょう"} )
|
63
|
+
@client.close
|
64
|
+
end
|
65
|
+
|
42
66
|
def test_expire
|
43
67
|
@client.open
|
44
68
|
assert_equal(@client.set_bulk( {"key1" => ["value1", 1]} ), 1) # expire after 1 second
|
@@ -55,15 +79,36 @@ class ClientTest < Test::Unit::TestCase
|
|
55
79
|
assert_equal(@client.get("key2"), "value2")
|
56
80
|
assert_equal(@client.get("key3"), "value3")
|
57
81
|
assert_equal(@client.get("key4"), nil)
|
82
|
+
@client.remove_bulk( ["key2", "key3"] )
|
83
|
+
@client.close
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_expire_multibyte_characters
|
87
|
+
@client.open
|
88
|
+
assert_equal(@client.set_bulk( {"あ" => ["あいのまち", 1]} ), 1) # expire after 1 second
|
89
|
+
assert_equal(@client.set_bulk( {"い" => "いしかずちょう"} ), 1) # not expire
|
90
|
+
assert_equal(@client.set("う", "ういろうのちょう"), true) # not expire
|
91
|
+
assert_equal(@client.set("え", "えびすがわ", 1), true) # expire after 1 second
|
92
|
+
|
93
|
+
assert_equal(@client.get("あ"), "あいのまち")
|
94
|
+
assert_equal(@client.get("い"), "いしかずちょう")
|
95
|
+
assert_equal(@client.get("う"), "ういろうのちょう")
|
96
|
+
assert_equal(@client.get("え"), "えびすがわ")
|
97
|
+
sleep 3
|
98
|
+
assert_equal(@client.get("あ"), nil)
|
99
|
+
assert_equal(@client.get("い"), "いしかずちょう")
|
100
|
+
assert_equal(@client.get("う"), "ういろうのちょう")
|
101
|
+
assert_equal(@client.get("え"), nil)
|
102
|
+
@client.remove_bulk( ["い", "う"] )
|
58
103
|
@client.close
|
59
104
|
end
|
60
105
|
|
61
106
|
def test_dbid
|
62
107
|
@client.open
|
63
|
-
assert_equal(@client.set_bulk( {"
|
64
|
-
assert_equal(@client.set_bulk( {"
|
65
|
-
assert_equal(@client.get("
|
66
|
-
assert_equal(@client.get("
|
108
|
+
assert_equal(@client.set_bulk( {"あ" => "あいのまち"}, 0 ), 1)
|
109
|
+
assert_equal(@client.set_bulk( {"あ" => "あいのまち"}, 1 ), 0)
|
110
|
+
assert_equal(@client.get("あ", 0), "あいのまち")
|
111
|
+
assert_equal(@client.get("あ", 1), nil)
|
67
112
|
@client.close
|
68
113
|
end
|
69
114
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kyototycoon-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|