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 +8 -8
- data/README.md +47 -24
- data/Rakefile +7 -0
- data/gibson.gemspec +2 -0
- data/lib/gibson/connection.rb +13 -2
- data/lib/gibson/gibson.rb +7 -4
- data/lib/gibson/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGMwMWUxNjZkZGExNDRkMGQ0Yzc0ZmUzNzQ5NmJlNzRlZjFiNzZlMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzRhOWRlNjJkMWY4N2YzMmFkODkzYTdiMDcwNjAyOTAzYzJlYjMyNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2NhZDk2NWVlODE0NDZjOTM2NTQ5NDYyNWIyMjZiNTk1OTIwNTM3NGNlMTZl
|
10
|
+
MjU2YWRiMzI0NzY0MDFiYjkyNjYwMzBhNzIxMmJlYmIwNDVmYzBiOTU1NjU1
|
11
|
+
ODQ1ZTQ4MzExNzc2MTUzZTI3ZWUwNTU3ZjM5MTA0NDM0NDRlZTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
25
|
+
```bash
|
26
|
+
gem install gibson
|
27
|
+
```
|
26
28
|
|
27
29
|
And
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
52
|
+
```ruby
|
53
|
+
require 'gibson'
|
40
54
|
|
41
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
76
|
-
|
94
|
+
```ruby
|
95
|
+
# will retrieve the 'key' value
|
96
|
+
gibson.get 'key'
|
77
97
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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.
|
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
|
-
|
116
|
+
```ruby
|
117
|
+
gibson.close
|
118
|
+
```
|
96
119
|
|
97
120
|
License
|
98
121
|
---
|
99
122
|
|
100
123
|
Released under the BSD license.
|
101
|
-
Copyright ©
|
124
|
+
Copyright © 2014, Simone Margaritelli
|
102
125
|
<evilsocket@gmail.com>
|
103
126
|
|
104
127
|
<http://www.evilsocket.net/>
|
data/Rakefile
CHANGED
data/gibson.gemspec
CHANGED
data/lib/gibson/connection.rb
CHANGED
@@ -81,8 +81,19 @@ module Gibson
|
|
81
81
|
##
|
82
82
|
# Read specified amount of data from the socket.
|
83
83
|
def read(n)
|
84
|
-
|
85
|
-
|
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
|
-
|
48
|
+
# number
|
49
49
|
elsif encoding == Protocol::ENCODINGS[:number]
|
50
|
-
|
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
|
|
data/lib/gibson/version.rb
CHANGED
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
|
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:
|
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:
|