tarantool 0.1 → 0.1.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 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
- Before all requests you must configure client:
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
- Low level part of client can work in two mode: EM deferrables and EM-Synchrony.
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
- High level part of client implements ActiveModel API: Callbacks, Validations, Serialization, Dirty. Its autocast types, choose right index for query and something more. So code looks like this:
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
- On record definition step, fields order are important, in that order they will be store in Tarantool. By default primary key is first field. `index` method just mapping to your Tarantool schema, client doesn't modify schema for you.
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
 
@@ -6,12 +6,12 @@ module Tarantool
6
6
  header_size 12
7
7
 
8
8
  def next_request_id
9
- @request_id ||= 0
10
- @request_id += 1
11
- if @request_id > 0xffffffff
12
- @request_id = 0
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
- @request_id
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[@request_id]
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
@@ -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('a*')
79
+ msg = data[4, data.size].unpack('A*')
80
80
  fail BadReturnCode.new("Error code #{return_code}: #{msg}")
81
81
  end
82
82
  end
@@ -32,7 +32,7 @@ module Tarantool
32
32
  request Requests::Ping, args
33
33
  end
34
34
 
35
- def request(cls, args)
35
+ def request(cls, args)
36
36
  cls.new(self, *args).perform
37
37
  end
38
38
  end
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 ||= Space.new connection, @config[:space_no]
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
@@ -10,7 +10,7 @@ require 'rr'
10
10
 
11
11
  require 'tarantool/synchrony'
12
12
 
13
- config = { host: '10.211.55.3', port: 33013, space_no: 0 }
13
+ config = { host: '192.168.127.128', port: 33013, space_no: 0 }
14
14
 
15
15
  Tarantool.configure config
16
16
 
@@ -109,6 +109,5 @@ describe Tarantool::Request do
109
109
  res.must_be_kind_of Numeric
110
110
  end
111
111
  end
112
-
113
112
  end
114
113
  end
data/tarantool.gemspec CHANGED
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'tarantool'
7
- s.version = '0.1'
8
- s.date = '2011-12-05'
7
+ s.version = '0.1.1'
8
+ s.date = '2011-12-13'
9
9
  s.rubyforge_project = 'tarantool'
10
10
 
11
11
  s.summary = "Tarantool KV-storage client."
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: '0.1'
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-05 00:00:00.000000000Z
12
+ date: 2011-12-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &70160133311300 !ruby/object:Gem::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: *70160133311300
27
+ version_requirements: *70194702023280
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: activemodel
30
- requirement: &70160133310540 !ruby/object:Gem::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: *70160133310540
41
+ version_requirements: *70194702022400
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: em-synchrony
44
- requirement: &70160133309780 !ruby/object:Gem::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: *70160133309780
55
+ version_requirements: *70194702021400
56
56
  description: Tarantool KV-storage client.
57
57
  email: ceo@prepor.ru
58
58
  executables: []