gibson 1.0.5 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGNhNDQ5NjU2NDZjZTdmNTI3NWFlZWYwZWY1ZDBiZDJkMjJlYTU5NQ==
4
+ ZGMwMWUxNjZkZGExNDRkMGQ0Yzc0ZmUzNzQ5NmJlNzRlZjFiNzZlMw==
5
5
  data.tar.gz: !binary |-
6
- ZTI3N2FkN2M4NmYwMWYyYmVkNjFhMDk0Y2QzYmM3NDcxMDhlOWRhMA==
6
+ NzRhOWRlNjJkMWY4N2YzMmFkODkzYTdiMDcwNjAyOTAzYzJlYjMyNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDQ2YTdlOWZjZjQwZDFlYWQ5MWFkY2JhMzkxMWQzOWU1NmFmZTBkOWFhMDFj
10
- NmE5MDRkNGUzOWU5MjJhMThkNjY2OTg0MzRiYmZlYzA0NTU1NmVjZmE3ZWI2
11
- ZWVlNzlhZDE5MjUzODgzMTU3MjljYTlmZDU0NDc5ZTgyNjVkZGM=
9
+ Y2NhZDk2NWVlODE0NDZjOTM2NTQ5NDYyNWIyMjZiNTk1OTIwNTM3NGNlMTZl
10
+ MjU2YWRiMzI0NzY0MDFiYjkyNjYwMzBhNzIxMmJlYmIwNDVmYzBiOTU1NjU1
11
+ ODQ1ZTQ4MzExNzc2MTUzZTI3ZWUwNTU3ZjM5MTA0NDM0NDRlZTc=
12
12
  data.tar.gz: !binary |-
13
- ZmJiNmY3NWRkMWY4ZmE4N2JmY2M4ZmJhYTQyNWFmNjhjYjNlMGUyYzUxOTQ2
14
- MjkxNTg1NGQ5NjFmMGZlMDhkN2JjOTA5MGRjMjEzOTM5YWZiZTZmZDk4NWZj
15
- N2IyYjZkMzk1MjU1NzkzYzhlYzBhYWRkNjMwODYyODMyODQwZmY=
13
+ ZWU4MWQ3MzU2ZTdhMmQ0YjMyM2VhOWM3OGM0MGVmMjUyNTRkMTdmNThjOWMz
14
+ MGQwOTI2ZjcxZDE2M2VhMDA4YWI1MDk5OWMxMzAzZTcyYTUyNjdjM2Y1OGFh
15
+ ZjQ5YmNmMWI4MzU1ZDM1ZWRmODI0ZmZmYjBiOGQyOGZkZjM4ZTI=
data/README.md CHANGED
@@ -22,23 +22,38 @@ Installation and Usage
22
22
 
23
23
  You can verify your installation using this piece of code:
24
24
 
25
- gem install gibson
25
+ ```bash
26
+ gem install gibson
27
+ ```
26
28
 
27
29
  And
28
30
 
29
- require 'gibson'
30
- g = Gibson::Client.new
31
- g.set 0, 'foo', 'bar'
32
- p g.get 'foo'
31
+ ```ruby
32
+ require 'gibson'
33
+ g = Gibson::Client.new
34
+ g.set 0, 'foo', 'bar'
35
+ p g.get 'foo'
36
+ ```
37
+
38
+ Tests
39
+ -----
40
+
41
+ Unit tests are provided inside the `test` folder, to run all of them:
42
+
43
+ ```bash
44
+ rake test
45
+ ```
33
46
 
34
47
  Connection
35
48
  ----------
36
49
 
37
50
  Create a Client object to start working.
38
51
 
39
- require 'gibson'
52
+ ```ruby
53
+ require 'gibson'
40
54
 
41
- gibson = Gibson::Client.new
55
+ gibson = Gibson::Client.new
56
+ ```
42
57
 
43
58
  The following options can be used in the constructor:
44
59
 
@@ -50,11 +65,15 @@ The following options can be used in the constructor:
50
65
 
51
66
  Tcp connection example:
52
67
 
53
- gibson = Gibson::Client.new :address => 'localhost'
68
+ ```ruby
69
+ gibson = Gibson::Client.new :address => 'localhost'
70
+ ```
54
71
 
55
72
  Custom unix socket connection example with 50ms timeout:
56
73
 
57
- gibson = Gibson::Client.new :socket => '/tmp/socket', :timeout => 50
74
+ ```ruby
75
+ gibson = Gibson::Client.new :socket => '/tmp/socket', :timeout => 50
76
+ ```
58
77
 
59
78
  Runtime Errors
60
79
  --------------
@@ -72,33 +91,37 @@ Methods
72
91
 
73
92
  After connecting, you can start to make requests.
74
93
 
75
- # will retrieve the 'key' value
76
- gibson.get 'key'
94
+ ```ruby
95
+ # will retrieve the 'key' value
96
+ gibson.get 'key'
77
97
 
78
- # create ( or replace ) a value with a TTL of 3600 seconds.
79
- # set the TTL to zero and the value will never expire.
80
- gibson.set 3600, 'key', 'value'
81
-
82
- # delete a key from cache.
83
- gibson.del 'key'
98
+ # create ( or replace ) a value with a TTL of 3600 seconds.
99
+ # set the TTL to zero and the value will never expire.
100
+ gibson.set 3600, 'key', 'value'
101
+
102
+ # delete a key from cache.
103
+ gibson.del 'key'
84
104
 
85
- # will print server stats
86
- gibson.stats.each do |name,value|
87
- puts "#{name}: #{value}"
88
- end
105
+ # will print server stats
106
+ gibson.stats.each do |name,value|
107
+ puts "#{name}: #{value}"
108
+ end
109
+ ```
89
110
 
90
111
  Every available command is automatically mapped to a client method, so follow the
91
- [official reference](http://gibson-db.in/commands.php) of Gibson commands.
112
+ [official reference](http://gibson-db.in/commands.html) of Gibson commands.
92
113
 
93
114
  Once you're done, close the connection.
94
115
 
95
- gibson.close
116
+ ```ruby
117
+ gibson.close
118
+ ```
96
119
 
97
120
  License
98
121
  ---
99
122
 
100
123
  Released under the BSD license.
101
- Copyright © 2013, Simone Margaritelli
124
+ Copyright © 2014, Simone Margaritelli
102
125
  <evilsocket@gmail.com>
103
126
 
104
127
  <http://www.evilsocket.net/>
data/Rakefile CHANGED
@@ -1,3 +1,10 @@
1
1
  require 'rake/clean'
2
+ require 'rake/testtask'
3
+
2
4
  CLEAN.include "**/*.rbc"
3
5
  CLEAN.include "**/.DS_Store"
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.options = "-v"
9
+ t.test_files = FileList["test/*test*.rb"]
10
+ end
data/gibson.gemspec CHANGED
@@ -19,5 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.rdoc_options = ["--charset=UTF-8"]
20
20
  s.require_paths = ["lib"]
21
21
  s.summary = %q{High performance Gibson client for Ruby}
22
+
23
+ s.add_development_dependency("rake")
22
24
  end
23
25
 
@@ -81,8 +81,19 @@ module Gibson
81
81
  ##
82
82
  # Read specified amount of data from the socket.
83
83
  def read(n)
84
- wait_readable
85
- @sock.recv n
84
+ read = 0
85
+ data = ""
86
+
87
+ while read < n do
88
+ wait_readable
89
+
90
+ left = n - read
91
+
92
+ data += @sock.recv left
93
+ read = data.size
94
+ end
95
+
96
+ data
86
97
  end
87
98
  end
88
99
  end
data/lib/gibson/gibson.rb CHANGED
@@ -45,10 +45,9 @@ module Gibson
45
45
  # plain string
46
46
  if encoding == Protocol::ENCODINGS[:plain]
47
47
  io.read_unpacked size, 'Z' + size.to_s
48
- # number
48
+ # number
49
49
  elsif encoding == Protocol::ENCODINGS[:number]
50
- unpacker = size == 4 ? 'l<' : 'q<'
51
- io.read_unpacked size, unpacker
50
+ io.read_unpacked size, size == 4 ? 'l<' : 'q<'
52
51
  else
53
52
  raise 'Unknown data encoding.'
54
53
  end
@@ -99,11 +98,15 @@ module Gibson
99
98
  psize = payload.length
100
99
  packet = [ 2 + psize, opcode, payload ].pack( 'L<S<Z' + psize.to_s )
101
100
 
102
- @connection.write packet
101
+ wrote = @connection.write packet
103
102
 
103
+ raise( Timeout::Error, "Couldn't complete writing ( wrote #{wrote} of #{packet.size} bytes )" ) unless packet.size == wrote
104
+
104
105
  code, encoding, size = @connection.read(7).unpack('S<cL<' )
105
106
  data = @connection.read size
106
107
 
108
+ raise( Timeout::Error, "Couldn't complete reading ( read #{data.size} of #{size} bytes )" ) unless data.size == size
109
+
107
110
  decode code, encoding, size, StringIO.new(data)
108
111
  end
109
112
 
@@ -1,4 +1,4 @@
1
1
  module Gibson
2
- VERSION = '1.0.5'
2
+ VERSION = '1.1.0'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gibson
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simone Margaritelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-18 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: High performance Gibson client for Ruby
14
28
  email: evilsocket@gmail.com
15
29
  executables: []
@@ -52,3 +66,4 @@ signing_key:
52
66
  specification_version: 4
53
67
  summary: High performance Gibson client for Ruby
54
68
  test_files: []
69
+ has_rdoc: