tarantool 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -6
- data/lib/tarantool/connection.rb +7 -7
- data/lib/tarantool/request.rb +1 -1
- data/lib/tarantool/space.rb +1 -1
- data/lib/tarantool.rb +9 -3
- data/spec/spec_helper.rb +1 -1
- data/spec/tarantool/request_spec.rb +0 -1
- data/tarantool.gemspec +2 -2
- metadata +8 -8
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# About
|
2
2
|
|
3
|
-
Its asynchronyous EventMachine ruby client for [Tarantool Key-Value Storage](github.com/mailru/tarantool).
|
3
|
+
Its asynchronyous EventMachine ruby client for [Tarantool Key-Value Storage](http://github.com/mailru/tarantool).
|
4
4
|
|
5
5
|
# Install
|
6
6
|
|
@@ -18,13 +18,14 @@ require 'tarantool/record'
|
|
18
18
|
|
19
19
|
# Usage
|
20
20
|
|
21
|
-
|
21
|
+
To be able to send requests to the server, you must
|
22
|
+
configure and establish a client connection:
|
22
23
|
|
23
24
|
```ruby
|
24
25
|
Tarantool.configure host: 'locahost', port: 33013, space_no: 0
|
25
26
|
```
|
26
27
|
|
27
|
-
|
28
|
+
The driver internals can work in two modes: EM deferrables and EM-Synchrony.
|
28
29
|
|
29
30
|
EM deferrables:
|
30
31
|
|
@@ -41,7 +42,7 @@ req.errback do |err|
|
|
41
42
|
end
|
42
43
|
```
|
43
44
|
|
44
|
-
Synchrony mode:
|
45
|
+
'Synchrony' mode:
|
45
46
|
|
46
47
|
```ruby
|
47
48
|
require 'tarantool/synchrony'
|
@@ -51,7 +52,9 @@ res = Tarantool.select 'prepor'
|
|
51
52
|
puts "Name: #{res.tuple[1].to_s}; Email: #{res.tuple[2].to_s}"
|
52
53
|
```
|
53
54
|
|
54
|
-
|
55
|
+
The driver itself provides ActiveModel API: Callbacks, Validations, Serialization, Dirty.
|
56
|
+
Type casting is automatic, based on the index type chosen to process the query.
|
57
|
+
For example:
|
55
58
|
|
56
59
|
```ruby
|
57
60
|
require 'tarantool/record'
|
@@ -104,7 +107,10 @@ User.find('prepor').info['bio'] # => 'hi!'
|
|
104
107
|
user.destroy
|
105
108
|
```
|
106
109
|
|
107
|
-
|
110
|
+
When definining a record, field order is important: this is the order of fields
|
111
|
+
in the tuple stored by Tarantool. By default, the primary key is field 0.
|
112
|
+
|
113
|
+
`index` method just mapping to your Tarantool schema, client doesn't modify schema for you.
|
108
114
|
|
109
115
|
# TODO
|
110
116
|
|
data/lib/tarantool/connection.rb
CHANGED
@@ -6,12 +6,12 @@ module Tarantool
|
|
6
6
|
header_size 12
|
7
7
|
|
8
8
|
def next_request_id
|
9
|
-
@
|
10
|
-
@
|
11
|
-
if @
|
12
|
-
@
|
9
|
+
@next_request_id ||= 0
|
10
|
+
@next_request_id += 1
|
11
|
+
if @next_request_id > 0xffffffff
|
12
|
+
@next_request_id = 0
|
13
13
|
end
|
14
|
-
@
|
14
|
+
@next_request_id
|
15
15
|
end
|
16
16
|
|
17
17
|
def connection_completed
|
@@ -28,8 +28,8 @@ module Tarantool
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def receive_body(data)
|
31
|
-
clb = waiting_requests
|
32
|
-
raise UnexpectedResponse.new("For request id #{request_id}") unless clb
|
31
|
+
clb = waiting_requests.delete @request_id
|
32
|
+
raise UnexpectedResponse.new("For request id #{@request_id}") unless clb
|
33
33
|
clb.call data
|
34
34
|
end
|
35
35
|
# end FixedHeaderAndBody API
|
data/lib/tarantool/request.rb
CHANGED
@@ -76,7 +76,7 @@ module Tarantool
|
|
76
76
|
if return_code == 0
|
77
77
|
succeed Response.new(data[4, data.size], response_params)
|
78
78
|
else
|
79
|
-
msg = data[4, data.size].unpack('
|
79
|
+
msg = data[4, data.size].unpack('A*')
|
80
80
|
fail BadReturnCode.new("Error code #{return_code}: #{msg}")
|
81
81
|
end
|
82
82
|
end
|
data/lib/tarantool/space.rb
CHANGED
data/lib/tarantool.rb
CHANGED
@@ -3,7 +3,7 @@ require 'eventmachine'
|
|
3
3
|
require 'em-synchrony'
|
4
4
|
|
5
5
|
module Tarantool
|
6
|
-
VERSION = '0.1'
|
6
|
+
VERSION = '0.1.1'
|
7
7
|
extend self
|
8
8
|
require 'tarantool/space'
|
9
9
|
require 'tarantool/connection'
|
@@ -13,21 +13,27 @@ module Tarantool
|
|
13
13
|
require 'tarantool/serializers'
|
14
14
|
|
15
15
|
def singleton_space
|
16
|
-
@singleton_space ||=
|
16
|
+
@singleton_space ||= space
|
17
17
|
end
|
18
18
|
|
19
|
-
def connection
|
19
|
+
def connection
|
20
20
|
@connection ||= begin
|
21
21
|
raise "Tarantool.configure before connect" unless @config
|
22
22
|
EM.connect @config[:host], @config[:port], Tarantool::Connection
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
def reset_connection
|
27
|
+
@connection = nil
|
28
|
+
@singleton_space = nil
|
29
|
+
end
|
30
|
+
|
26
31
|
def space(no = nil)
|
27
32
|
Space.new connection, no || @config[:space_no]
|
28
33
|
end
|
29
34
|
|
30
35
|
def configure(config = {})
|
36
|
+
EM.add_shutdown_hook { reset_connection }
|
31
37
|
@config = config
|
32
38
|
end
|
33
39
|
|
data/spec/spec_helper.rb
CHANGED
data/tarantool.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tarantool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-13 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
16
|
-
requirement: &
|
16
|
+
requirement: &70194702023280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
version: 2.0.0
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
|
-
version_requirements: *
|
27
|
+
version_requirements: *70194702023280
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: activemodel
|
30
|
-
requirement: &
|
30
|
+
requirement: &70194702022400 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ! '>='
|
@@ -38,10 +38,10 @@ dependencies:
|
|
38
38
|
version: '4.0'
|
39
39
|
type: :runtime
|
40
40
|
prerelease: false
|
41
|
-
version_requirements: *
|
41
|
+
version_requirements: *70194702022400
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: em-synchrony
|
44
|
-
requirement: &
|
44
|
+
requirement: &70194702021400 !ruby/object:Gem::Requirement
|
45
45
|
none: false
|
46
46
|
requirements:
|
47
47
|
- - ! '>='
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
version: '2.0'
|
53
53
|
type: :runtime
|
54
54
|
prerelease: false
|
55
|
-
version_requirements: *
|
55
|
+
version_requirements: *70194702021400
|
56
56
|
description: Tarantool KV-storage client.
|
57
57
|
email: ceo@prepor.ru
|
58
58
|
executables: []
|