oxblood 0.1.0.dev2 → 0.1.0.dev3
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 +4 -4
- data/.codeclimate.yml +2 -0
- data/.gitignore +2 -1
- data/lib/oxblood/command.rb +9 -1
- data/lib/oxblood/connection.rb +43 -43
- data/lib/oxblood/session.rb +39 -5
- data/lib/oxblood/version.rb +1 -1
- data/tmp/.keep +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d7a859b01da306481014391452d354b78e733d9
|
4
|
+
data.tar.gz: b5b6a5ccc51f7b07c562c29b434a85f65b9bd4cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1dffe945b9bb71adec19fc0f33a6847ca90fa325d061f699e7b784ced2aedcc4ec0f7685a17764e94db4f2ca513e830f0233e7a379b89a75584409f08862ce0
|
7
|
+
data.tar.gz: 53ccf202c3821c309a5d7e4c998280f682f7197d54f9c2f2cb6e7295bd07acb7054a5b4df50086e7b604a91f2911301d79677f416dcd8dd046a2202ec561b42e
|
data/.codeclimate.yml
CHANGED
data/.gitignore
CHANGED
data/lib/oxblood/command.rb
CHANGED
@@ -61,7 +61,7 @@ module Oxblood
|
|
61
61
|
serialize([:HVALS, key])
|
62
62
|
end
|
63
63
|
|
64
|
-
def hscan(
|
64
|
+
def hscan(_key, _cursor)
|
65
65
|
raise 'Not implemented!'
|
66
66
|
end
|
67
67
|
|
@@ -69,6 +69,10 @@ module Oxblood
|
|
69
69
|
|
70
70
|
# ------------------ Connection ---------------------
|
71
71
|
|
72
|
+
def auth(password)
|
73
|
+
serialize([:AUTH, password])
|
74
|
+
end
|
75
|
+
|
72
76
|
def ping(message = nil)
|
73
77
|
command = [:PING]
|
74
78
|
command << message if message
|
@@ -76,6 +80,10 @@ module Oxblood
|
|
76
80
|
serialize(command)
|
77
81
|
end
|
78
82
|
|
83
|
+
def select(index)
|
84
|
+
serialize([:SELECT, index])
|
85
|
+
end
|
86
|
+
|
79
87
|
# ------------------ Server ---------------------
|
80
88
|
|
81
89
|
def info(section = nil)
|
data/lib/oxblood/connection.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'oxblood/protocol'
|
2
2
|
require 'oxblood/buffered_io'
|
3
|
+
require 'oxblood/session'
|
3
4
|
|
4
5
|
module Oxblood
|
5
6
|
# Class responsible for connection maintenance
|
@@ -7,54 +8,51 @@ module Oxblood
|
|
7
8
|
TimeoutError = Class.new(RuntimeError)
|
8
9
|
|
9
10
|
class << self
|
10
|
-
# Open Redis
|
11
|
+
# Open connection to Redis server
|
11
12
|
#
|
12
|
-
# @param [Hash]
|
13
|
+
# @param [Hash] opts Connection options
|
13
14
|
#
|
14
|
-
# @option (
|
15
|
-
# @option
|
16
|
-
|
17
|
-
options.key?(:path) ? connect_unix(options) : connect_tcp(options)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Connect to Redis server through TCP
|
15
|
+
# @option opts [Float] :timeout (1.0) socket read timeout
|
16
|
+
# @option opts [Integer] :db database number
|
17
|
+
# @option opts [String] :password
|
21
18
|
#
|
22
|
-
# @
|
19
|
+
# @option opts [String] :host ('localhost') Hostname or IP address to connect to
|
20
|
+
# @option opts [Integer] :port (6379) Port Redis server listens on
|
21
|
+
# @option opts [Float] :connect_timeout (1.0) socket connect timeout
|
23
22
|
#
|
24
|
-
# @option
|
25
|
-
# @option options [Integer] :port (5672) Port Redis server listens on
|
26
|
-
# @option options [Float] :timeout (1.0) socket read timeout
|
27
|
-
# @option options [Float] :connect_timeout (1.0) socket connect timeout
|
23
|
+
# @option opts [String] :path UNIX socket path
|
28
24
|
#
|
29
25
|
# @return [Oxblood::Connection] connection instance
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
def open(opts = {})
|
27
|
+
socket = if opts.key?(:path)
|
28
|
+
unix_socket(opts.fetch(:path))
|
29
|
+
else
|
30
|
+
host = opts.fetch(:host, 'localhost')
|
31
|
+
port = opts.fetch(:port, 6379)
|
32
|
+
connect_timeout = opts.fetch(:connect_timeout, 1.0)
|
33
|
+
|
34
|
+
tcp_socket(host, port, connect_timeout)
|
35
|
+
end
|
36
|
+
|
37
|
+
timeout = opts.fetch(:timeout, 1.0)
|
38
|
+
|
39
|
+
new(socket, timeout).tap do |conn|
|
40
|
+
session = Session.new(conn)
|
41
|
+
session.auth!(opts[:password]) if opts[:password]
|
42
|
+
session.select(opts[:db]) if opts[:db]
|
43
|
+
end
|
44
|
+
end
|
35
45
|
|
36
|
-
|
37
|
-
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
46
|
+
private
|
38
47
|
|
39
|
-
|
48
|
+
def unix_socket(path)
|
49
|
+
UNIXSocket.new(path)
|
40
50
|
end
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
# @option options [String] :path UNIX socket path
|
47
|
-
# @option options [Float] :timeout (1.0) socket read timeout
|
48
|
-
#
|
49
|
-
# @raise [KeyError] if :path was not passed
|
50
|
-
#
|
51
|
-
# @return [Oxblood::Connection] connection instance
|
52
|
-
def connect_unix(options = {})
|
53
|
-
path = options.fetch(:path)
|
54
|
-
timeout = options.fetch(:timeout, 1.0)
|
55
|
-
|
56
|
-
socket = ::Socket.unix(path)
|
57
|
-
new(socket, timeout)
|
52
|
+
def tcp_socket(host, port, connect_timeout)
|
53
|
+
Socket.tcp(host, port, connect_timeout: connect_timeout).tap do |sock|
|
54
|
+
sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
55
|
+
end
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
@@ -72,15 +70,16 @@ module Oxblood
|
|
72
70
|
write(Protocol.build_command(command))
|
73
71
|
end
|
74
72
|
|
75
|
-
#
|
76
|
-
|
77
|
-
|
73
|
+
# Write data to socket
|
74
|
+
# @param [#to_s] data given
|
75
|
+
# @return [Integer] the number of bytes written
|
76
|
+
def write(data)
|
77
|
+
@socket.write(data)
|
78
78
|
end
|
79
79
|
|
80
80
|
# Send command to Redis server and read response from it
|
81
81
|
# @example run_command(['PING']) => PONG
|
82
82
|
# @param [Array] command Array of command name with it's args
|
83
|
-
# @return #FIXME
|
84
83
|
def run_command(command)
|
85
84
|
send_command(command)
|
86
85
|
read_response
|
@@ -129,7 +128,8 @@ module Oxblood
|
|
129
128
|
Protocol.parse(self)
|
130
129
|
end
|
131
130
|
|
132
|
-
#
|
131
|
+
# Read several responses from server
|
132
|
+
# (see #read_response)
|
133
133
|
def read_responses(n)
|
134
134
|
Array.new(n) { read_response }
|
135
135
|
end
|
data/lib/oxblood/session.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'oxblood/connection'
|
2
1
|
require 'oxblood/command'
|
3
2
|
|
4
3
|
module Oxblood
|
@@ -185,6 +184,28 @@ module Oxblood
|
|
185
184
|
|
186
185
|
# ------------------ Connection ---------------------
|
187
186
|
|
187
|
+
# Authenticate to the server
|
188
|
+
# @see http://redis.io/commands/auth
|
189
|
+
#
|
190
|
+
# @param [String] password
|
191
|
+
#
|
192
|
+
# @return [String] 'OK'
|
193
|
+
def auth(password)
|
194
|
+
run(cmd.auth(password))
|
195
|
+
end
|
196
|
+
|
197
|
+
# Like {#auth}, except that if error returned, raises it.
|
198
|
+
#
|
199
|
+
# @param [String] password
|
200
|
+
#
|
201
|
+
# @raise [Protocol::RError] if error returned
|
202
|
+
#
|
203
|
+
# @return [String] 'OK'
|
204
|
+
def auth!(password)
|
205
|
+
response = auth(password)
|
206
|
+
error?(response) ? (raise response) : response
|
207
|
+
end
|
208
|
+
|
188
209
|
# Returns PONG if no argument is provided, otherwise return a copy of
|
189
210
|
# the argument as a bulk
|
190
211
|
# @see http://redis.io/commands/ping
|
@@ -196,6 +217,16 @@ module Oxblood
|
|
196
217
|
run(cmd.ping(message))
|
197
218
|
end
|
198
219
|
|
220
|
+
# Change the selected database for the current connection
|
221
|
+
# @see http://redis.io/commands/select
|
222
|
+
#
|
223
|
+
# @param [Integer] index database to switch
|
224
|
+
#
|
225
|
+
# @return [String] 'OK'
|
226
|
+
def select(index)
|
227
|
+
run(cmd.select(index))
|
228
|
+
end
|
229
|
+
|
199
230
|
# ------------------ Server ---------------------
|
200
231
|
|
201
232
|
# Returns information and statistics about the server in a format that is
|
@@ -204,10 +235,7 @@ module Oxblood
|
|
204
235
|
#
|
205
236
|
# @param [String] section used to select a specific section of information
|
206
237
|
def info(section = nil)
|
207
|
-
|
208
|
-
command << section if section
|
209
|
-
|
210
|
-
response = run(cmd.info(section))
|
238
|
+
run(cmd.info(section))
|
211
239
|
# FIXME: Parse response
|
212
240
|
end
|
213
241
|
|
@@ -304,5 +332,11 @@ module Oxblood
|
|
304
332
|
@connection.write(command)
|
305
333
|
@connection.read_response
|
306
334
|
end
|
335
|
+
|
336
|
+
private
|
337
|
+
|
338
|
+
def error?(response)
|
339
|
+
Protocol::RError === response
|
340
|
+
end
|
307
341
|
end
|
308
342
|
end
|
data/lib/oxblood/version.rb
CHANGED
data/tmp/.keep
ADDED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oxblood
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.dev3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Shabanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/oxblood/version.rb
|
124
124
|
- lib/redis/connection/oxblood.rb
|
125
125
|
- oxblood.gemspec
|
126
|
+
- tmp/.keep
|
126
127
|
homepage: https://github.com/etehtsea/oxblood
|
127
128
|
licenses:
|
128
129
|
- MIT
|