oxblood 0.1.0.dev3 → 0.1.0.dev4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/benchmarks/serializer.rb +6 -5
- data/lib/oxblood/connection.rb +6 -6
- data/lib/oxblood/pipeline.rb +2 -3
- data/lib/oxblood/protocol.rb +11 -5
- data/lib/oxblood/session.rb +29 -31
- data/lib/oxblood/version.rb +1 -1
- data/lib/redis/connection/oxblood.rb +8 -3
- metadata +1 -2
- data/lib/oxblood/command.rb +0 -138
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a369a489b3733b77b4742e0d35cbaf30f8a794f
|
4
|
+
data.tar.gz: 081150bc06a0c6c2d3dd280f7ac0405caabd46a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86727e0c5bcfb0960204d6bd5e516d21614a9fb992e9d1cfe7c424872c759dc2673e1faafd2f82ca7035f64524f6f46839498ff0811e018045c854bb6e32467c
|
7
|
+
data.tar.gz: 24d72c0595245b1f19950acd2f65ae1ce19c32a9eed0b37893e9543bda7fb42b48523bd55511e5c87150260f5926e5a7de9f4502bffdc7152ed2df6945e250e1
|
data/benchmarks/serializer.rb
CHANGED
@@ -5,13 +5,14 @@ require 'redis/connection/command_helper'
|
|
5
5
|
CommandHelper = Object.new.tap { |o| o.extend Redis::Connection::CommandHelper }
|
6
6
|
|
7
7
|
command = [:set, 'foo', ['bar', Float::INFINITY, -Float::INFINITY, 3]]
|
8
|
-
|
9
|
-
|
10
|
-
p
|
11
|
-
|
8
|
+
command_name = :set
|
9
|
+
command_args = ['foo', ['bar', Float::INFINITY, -Float::INFINITY, 3]]
|
10
|
+
p ch_result = CommandHelper.build_command(command)
|
11
|
+
p ox_result = Oxblood::Protocol.build_command(command_name, *command_args)
|
12
|
+
raise unless ch_result == ox_result
|
12
13
|
|
13
14
|
Benchmark.ips do |x|
|
14
15
|
x.config(warmup: 20, benchmark: 10)
|
15
16
|
x.report('redis-ruby') { CommandHelper.build_command(command) }
|
16
|
-
x.report('Oxblood') { Oxblood::Protocol.build_command(
|
17
|
+
x.report('Oxblood') { Oxblood::Protocol.build_command(command_name, *command_args) }
|
17
18
|
end
|
data/lib/oxblood/connection.rb
CHANGED
@@ -63,11 +63,11 @@ module Oxblood
|
|
63
63
|
end
|
64
64
|
|
65
65
|
# Send comand to Redis server
|
66
|
-
# @example send_command(
|
66
|
+
# @example send_command('CONFIG', 'GET', '*') => 32
|
67
67
|
# @param [Array] command Array of command name with it's args
|
68
68
|
# @return [Integer] Number of bytes written to socket
|
69
|
-
def send_command(command)
|
70
|
-
write(Protocol.build_command(command))
|
69
|
+
def send_command(*command)
|
70
|
+
write(Protocol.build_command(*command))
|
71
71
|
end
|
72
72
|
|
73
73
|
# Write data to socket
|
@@ -78,10 +78,10 @@ module Oxblood
|
|
78
78
|
end
|
79
79
|
|
80
80
|
# Send command to Redis server and read response from it
|
81
|
-
# @example run_command(
|
81
|
+
# @example run_command('PING') => PONG
|
82
82
|
# @param [Array] command Array of command name with it's args
|
83
|
-
def run_command(command)
|
84
|
-
send_command(command)
|
83
|
+
def run_command(*command)
|
84
|
+
send_command(*command)
|
85
85
|
read_response
|
86
86
|
end
|
87
87
|
|
data/lib/oxblood/pipeline.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'oxblood/command'
|
2
|
-
|
3
1
|
module Oxblood
|
4
2
|
class Pipeline < Session
|
5
3
|
def initialize(connection)
|
@@ -12,7 +10,8 @@ module Oxblood
|
|
12
10
|
end
|
13
11
|
|
14
12
|
def sync
|
15
|
-
@
|
13
|
+
serialized_commands = @commands.map { |c| serialize(command) }
|
14
|
+
@connection.write(serialized_commands.join)
|
16
15
|
@connection.read_responses(@commands.size)
|
17
16
|
end
|
18
17
|
end
|
data/lib/oxblood/protocol.rb
CHANGED
@@ -92,13 +92,19 @@ module Oxblood
|
|
92
92
|
# @note Written in non-idiomatic ruby without error handling due to
|
93
93
|
# performance reasons
|
94
94
|
# @see http://www.redis.io/topics/protocol#sending-commands-to-a-redis-server
|
95
|
+
#
|
95
96
|
# @raise [SerializerError] if unable to serialize given command
|
96
|
-
#
|
97
|
+
#
|
98
|
+
# @param [#to_s] command name
|
99
|
+
# @param [Array] args array consisting of command arguments
|
100
|
+
#
|
97
101
|
# @return [String] serialized command
|
98
|
-
def build_command(command)
|
99
|
-
|
100
|
-
|
101
|
-
command.
|
102
|
+
def build_command(command = nil, *args)
|
103
|
+
return EMPTY_ARRAY_RESPONSE if command.nil?
|
104
|
+
|
105
|
+
result = append!(command, COMMAND_HEADER.dup)
|
106
|
+
size = 1
|
107
|
+
args.each do |c|
|
102
108
|
if Array === c
|
103
109
|
c.each do |e|
|
104
110
|
append!(e, result)
|
data/lib/oxblood/session.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'oxblood/command'
|
2
|
-
|
3
1
|
module Oxblood
|
4
2
|
class Session
|
5
3
|
def initialize(connection)
|
@@ -18,7 +16,7 @@ module Oxblood
|
|
18
16
|
#
|
19
17
|
# @return [Integer] the number of fields that were removed from the hash
|
20
18
|
def hdel(key, fields)
|
21
|
-
run(
|
19
|
+
run(:HDEL, key, fields)
|
22
20
|
end
|
23
21
|
|
24
22
|
# Returns if field is an existing field in the hash stored at key
|
@@ -29,7 +27,7 @@ module Oxblood
|
|
29
27
|
#
|
30
28
|
# @return [Boolean] do hash contains field or not
|
31
29
|
def hexists(key, field)
|
32
|
-
1 == run(
|
30
|
+
1 == run(:HEXISTS, key, field)
|
33
31
|
end
|
34
32
|
|
35
33
|
# Get the value of a hash field
|
@@ -41,7 +39,7 @@ module Oxblood
|
|
41
39
|
# @return [String, nil] the value associated with field
|
42
40
|
# or nil when field is not present in the hash or key does not exist.
|
43
41
|
def hget(key, field)
|
44
|
-
run(
|
42
|
+
run(:HGET, key, field)
|
45
43
|
end
|
46
44
|
|
47
45
|
# Get all the fields and values in a hash
|
@@ -51,7 +49,7 @@ module Oxblood
|
|
51
49
|
#
|
52
50
|
# @return [Hash] of fields and their values
|
53
51
|
def hgetall(key)
|
54
|
-
Hash[*run(
|
52
|
+
Hash[*run(:HGETALL, key)]
|
55
53
|
end
|
56
54
|
|
57
55
|
# Increment the integer value of a hash field by the given number
|
@@ -63,7 +61,7 @@ module Oxblood
|
|
63
61
|
#
|
64
62
|
# @return [Integer] the value at field after the increment operation
|
65
63
|
def hincrby(key, field, increment)
|
66
|
-
run(
|
64
|
+
run(:HINCRBY, key, field, increment)
|
67
65
|
end
|
68
66
|
|
69
67
|
# Increment the float value of a hash field by the given number
|
@@ -75,7 +73,7 @@ module Oxblood
|
|
75
73
|
#
|
76
74
|
# @return [String] the value of field after the increment
|
77
75
|
def hincrbyfloat(key, field, increment)
|
78
|
-
run(
|
76
|
+
run(:HINCRBYFLOAT, key, field, increment)
|
79
77
|
end
|
80
78
|
|
81
79
|
# Get all the keys in a hash
|
@@ -86,7 +84,7 @@ module Oxblood
|
|
86
84
|
# @return [Array] list of fields in the hash, or an empty list when
|
87
85
|
# key does not exist.
|
88
86
|
def hkeys(key)
|
89
|
-
run(
|
87
|
+
run(:HKEYS, key)
|
90
88
|
end
|
91
89
|
|
92
90
|
# Get the number of keys in a hash
|
@@ -97,7 +95,7 @@ module Oxblood
|
|
97
95
|
# @return [Integer] number of fields in the hash, or 0 when
|
98
96
|
# key does not exist.
|
99
97
|
def hlen(key)
|
100
|
-
run(
|
98
|
+
run(:HLEN, key)
|
101
99
|
end
|
102
100
|
|
103
101
|
# Get the field values of all given hash fields
|
@@ -109,7 +107,7 @@ module Oxblood
|
|
109
107
|
# @return [Array] list of values associated with the given fields,
|
110
108
|
# in the same order as they are requested.
|
111
109
|
def hmget(key, *fields)
|
112
|
-
run(
|
110
|
+
run(*fields.unshift(:HMGET, key))
|
113
111
|
end
|
114
112
|
|
115
113
|
# Set multiple hash fields to multiple values
|
@@ -120,7 +118,7 @@ module Oxblood
|
|
120
118
|
#
|
121
119
|
# @return [String] 'OK'
|
122
120
|
def hmset(key, *args)
|
123
|
-
run(
|
121
|
+
run(*args.unshift(:HMSET, key))
|
124
122
|
end
|
125
123
|
|
126
124
|
|
@@ -134,7 +132,7 @@ module Oxblood
|
|
134
132
|
# @return [Integer] 1 if field is a new field in the hash and value was set.
|
135
133
|
# 0 if field already exists in the hash and the value was updated.
|
136
134
|
def hset(key, field, value)
|
137
|
-
run(
|
135
|
+
run(:HSET, key, field, value)
|
138
136
|
end
|
139
137
|
|
140
138
|
# Set the value of a hash field, only if the field does not exist
|
@@ -147,7 +145,7 @@ module Oxblood
|
|
147
145
|
# @return [Integer] 1 if field is a new field in the hash and value was set.
|
148
146
|
# 0 if field already exists in the hash and no operation was performed.
|
149
147
|
def hsetnx(key, field, value)
|
150
|
-
run(
|
148
|
+
run(:HSETNX, key, field, value)
|
151
149
|
end
|
152
150
|
|
153
151
|
# Get the length of the value of a hash field
|
@@ -159,7 +157,7 @@ module Oxblood
|
|
159
157
|
# @return [Integer] the string length of the value associated with field,
|
160
158
|
# or 0 when field is not present in the hash or key does not exist at all.
|
161
159
|
def hstrlen(key, field)
|
162
|
-
run(
|
160
|
+
run(:HSTRLEN, key, field)
|
163
161
|
end
|
164
162
|
|
165
163
|
# Get all values in a hash
|
@@ -170,7 +168,7 @@ module Oxblood
|
|
170
168
|
# @return [Array] list of values in the hash, or an empty list when
|
171
169
|
# key does not exist
|
172
170
|
def hvals(key)
|
173
|
-
run(
|
171
|
+
run(:HVALS, key)
|
174
172
|
end
|
175
173
|
|
176
174
|
# Incrementally iterate hash fields and associated values
|
@@ -191,7 +189,7 @@ module Oxblood
|
|
191
189
|
#
|
192
190
|
# @return [String] 'OK'
|
193
191
|
def auth(password)
|
194
|
-
run(
|
192
|
+
run(:AUTH, password)
|
195
193
|
end
|
196
194
|
|
197
195
|
# Like {#auth}, except that if error returned, raises it.
|
@@ -214,7 +212,7 @@ module Oxblood
|
|
214
212
|
#
|
215
213
|
# @return [String] message passed as argument
|
216
214
|
def ping(message = nil)
|
217
|
-
run(
|
215
|
+
message ? run(:PING, message) : run(:PING)
|
218
216
|
end
|
219
217
|
|
220
218
|
# Change the selected database for the current connection
|
@@ -224,7 +222,7 @@ module Oxblood
|
|
224
222
|
#
|
225
223
|
# @return [String] 'OK'
|
226
224
|
def select(index)
|
227
|
-
run(
|
225
|
+
run(:SELECT, index)
|
228
226
|
end
|
229
227
|
|
230
228
|
# ------------------ Server ---------------------
|
@@ -235,7 +233,7 @@ module Oxblood
|
|
235
233
|
#
|
236
234
|
# @param [String] section used to select a specific section of information
|
237
235
|
def info(section = nil)
|
238
|
-
run(
|
236
|
+
section ? run(:INFO, section) : run(:INFO)
|
239
237
|
# FIXME: Parse response
|
240
238
|
end
|
241
239
|
|
@@ -248,7 +246,7 @@ module Oxblood
|
|
248
246
|
#
|
249
247
|
# @return [Integer] the number of keys that were removed
|
250
248
|
def del(*keys)
|
251
|
-
run(
|
249
|
+
run(*keys.unshift(:DEL))
|
252
250
|
end
|
253
251
|
|
254
252
|
# Find all keys matching the given pattern
|
@@ -256,7 +254,7 @@ module Oxblood
|
|
256
254
|
#
|
257
255
|
# @param [String] pattern used to match keys
|
258
256
|
def keys(pattern)
|
259
|
-
run(
|
257
|
+
run(:KEYS, pattern)
|
260
258
|
end
|
261
259
|
|
262
260
|
# Set a key's time to live in seconds
|
@@ -268,7 +266,7 @@ module Oxblood
|
|
268
266
|
# @return [Integer] 1 if the timeout was set. 0 if key does not exist or
|
269
267
|
# the timeout could not be set.
|
270
268
|
def expire(key, seconds)
|
271
|
-
run(
|
269
|
+
run(:EXPIRE, key, seconds)
|
272
270
|
end
|
273
271
|
|
274
272
|
# ------------------ Sets ------------------------
|
@@ -282,7 +280,7 @@ module Oxblood
|
|
282
280
|
# @return [Integer] the number of elements that were added to the set,
|
283
281
|
# not including all the elements already present into the set.
|
284
282
|
def sadd(key, *members)
|
285
|
-
run(
|
283
|
+
run(*members.unshift(:SADD, key))
|
286
284
|
end
|
287
285
|
|
288
286
|
# Add multiple sets
|
@@ -292,7 +290,7 @@ module Oxblood
|
|
292
290
|
#
|
293
291
|
# @return [Array] list with members of the resulting set
|
294
292
|
def sunion(*keys)
|
295
|
-
run(
|
293
|
+
run(*keys.unshift(:SUNION))
|
296
294
|
end
|
297
295
|
|
298
296
|
# ------------------ Sorted Sets -----------------
|
@@ -307,7 +305,7 @@ module Oxblood
|
|
307
305
|
# @param [String] key under which store set
|
308
306
|
# @param [[Float, String], Array<[Float, String]>] args scores and members
|
309
307
|
def zadd(key, *args)
|
310
|
-
run(
|
308
|
+
run(*args.unshift(:ZADD, key))
|
311
309
|
end
|
312
310
|
|
313
311
|
# Return a range of members in a sorted set, by score
|
@@ -319,17 +317,17 @@ module Oxblood
|
|
319
317
|
# @param [String] min value
|
320
318
|
# @param [String] max value
|
321
319
|
def zrangebyscore(key, min, max)
|
322
|
-
run(
|
320
|
+
run(:ZRANGEBYSCORE, key, min, max)
|
323
321
|
end
|
324
322
|
|
325
323
|
protected
|
326
324
|
|
327
|
-
def
|
328
|
-
|
325
|
+
def serialize(*command)
|
326
|
+
Protocol.build_command(*command)
|
329
327
|
end
|
330
328
|
|
331
|
-
def run(command)
|
332
|
-
@connection.write(command)
|
329
|
+
def run(*command)
|
330
|
+
@connection.write(serialize(*command))
|
333
331
|
@connection.read_response
|
334
332
|
end
|
335
333
|
|
data/lib/oxblood/version.rb
CHANGED
@@ -6,8 +6,11 @@ class Redis
|
|
6
6
|
module Connection
|
7
7
|
class Oxblood
|
8
8
|
def self.connect(config)
|
9
|
-
|
10
|
-
|
9
|
+
unless config[:path]
|
10
|
+
config = config.dup
|
11
|
+
config.delete(:path)
|
12
|
+
end
|
13
|
+
connection = ::Oxblood::Connection.open(config)
|
11
14
|
|
12
15
|
new(connection)
|
13
16
|
end
|
@@ -29,7 +32,7 @@ class Redis
|
|
29
32
|
end
|
30
33
|
|
31
34
|
def write(command)
|
32
|
-
@connection.send_command(command)
|
35
|
+
@connection.send_command(*command)
|
33
36
|
end
|
34
37
|
|
35
38
|
def read
|
@@ -39,6 +42,8 @@ class Redis
|
|
39
42
|
reply
|
40
43
|
rescue ::Oxblood::Protocol::ParserError => e
|
41
44
|
raise Redis::ProtocolError.new(e.message)
|
45
|
+
rescue ::Oxblood::Connection::TimeoutError => e
|
46
|
+
raise Redis::TimeoutError.new(e.message)
|
42
47
|
end
|
43
48
|
|
44
49
|
if defined?(Encoding::default_external)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.dev4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Shabanov
|
@@ -114,7 +114,6 @@ files:
|
|
114
114
|
- benchmarks/serializer.rb
|
115
115
|
- lib/oxblood.rb
|
116
116
|
- lib/oxblood/buffered_io.rb
|
117
|
-
- lib/oxblood/command.rb
|
118
117
|
- lib/oxblood/connection.rb
|
119
118
|
- lib/oxblood/pipeline.rb
|
120
119
|
- lib/oxblood/pool.rb
|
data/lib/oxblood/command.rb
DELETED
@@ -1,138 +0,0 @@
|
|
1
|
-
module Oxblood
|
2
|
-
module Command
|
3
|
-
class << self
|
4
|
-
#
|
5
|
-
# Hashes
|
6
|
-
#
|
7
|
-
|
8
|
-
def hdel(key, fields)
|
9
|
-
serialize([:HDEL, key, fields])
|
10
|
-
end
|
11
|
-
|
12
|
-
def hexists(key, field)
|
13
|
-
serialize([:HEXISTS, key, field])
|
14
|
-
end
|
15
|
-
|
16
|
-
def hget(key, field)
|
17
|
-
serialize([:HGET, key, field])
|
18
|
-
end
|
19
|
-
|
20
|
-
def hgetall(key)
|
21
|
-
serialize([:HGETALL, key])
|
22
|
-
end
|
23
|
-
|
24
|
-
def hincrby(key, field, increment)
|
25
|
-
serialize([:HINCRBY, key, field, increment])
|
26
|
-
end
|
27
|
-
|
28
|
-
def hincrbyfloat(key, field, increment)
|
29
|
-
serialize([:HINCRBYFLOAT, key, field, increment])
|
30
|
-
end
|
31
|
-
|
32
|
-
def hkeys(key)
|
33
|
-
serialize([:HKEYS, key])
|
34
|
-
end
|
35
|
-
|
36
|
-
def hlen(key)
|
37
|
-
serialize([:HLEN, key])
|
38
|
-
end
|
39
|
-
|
40
|
-
def hmget(key, *fields)
|
41
|
-
serialize(fields.unshift(:HMGET, key))
|
42
|
-
end
|
43
|
-
|
44
|
-
def hmset(key, *args)
|
45
|
-
serialize(args.unshift(:HMSET, key))
|
46
|
-
end
|
47
|
-
|
48
|
-
def hset(key, field, value)
|
49
|
-
serialize([:HSET, key, field, value])
|
50
|
-
end
|
51
|
-
|
52
|
-
def hsetnx(key, field, value)
|
53
|
-
serialize([:HSETNX, key, field, value])
|
54
|
-
end
|
55
|
-
|
56
|
-
def hstrlen(key, field)
|
57
|
-
serialize([:HSTRLEN, key, field])
|
58
|
-
end
|
59
|
-
|
60
|
-
def hvals(key)
|
61
|
-
serialize([:HVALS, key])
|
62
|
-
end
|
63
|
-
|
64
|
-
def hscan(_key, _cursor)
|
65
|
-
raise 'Not implemented!'
|
66
|
-
end
|
67
|
-
|
68
|
-
# ------------------ Strings ---------------------
|
69
|
-
|
70
|
-
# ------------------ Connection ---------------------
|
71
|
-
|
72
|
-
def auth(password)
|
73
|
-
serialize([:AUTH, password])
|
74
|
-
end
|
75
|
-
|
76
|
-
def ping(message = nil)
|
77
|
-
command = [:PING]
|
78
|
-
command << message if message
|
79
|
-
|
80
|
-
serialize(command)
|
81
|
-
end
|
82
|
-
|
83
|
-
def select(index)
|
84
|
-
serialize([:SELECT, index])
|
85
|
-
end
|
86
|
-
|
87
|
-
# ------------------ Server ---------------------
|
88
|
-
|
89
|
-
def info(section = nil)
|
90
|
-
command = [:INFO]
|
91
|
-
command << section if section
|
92
|
-
|
93
|
-
serialize(command)
|
94
|
-
end
|
95
|
-
|
96
|
-
# ------------------ Keys ------------------------
|
97
|
-
|
98
|
-
def del(*keys)
|
99
|
-
serialize(keys.unshift(:DEL))
|
100
|
-
end
|
101
|
-
|
102
|
-
def keys(pattern)
|
103
|
-
serialize([:KEYS, pattern])
|
104
|
-
end
|
105
|
-
|
106
|
-
def expire(key, seconds)
|
107
|
-
serialize([:EXPIRE, key, seconds])
|
108
|
-
end
|
109
|
-
|
110
|
-
# ------------------ Sets ------------------------
|
111
|
-
|
112
|
-
def sadd(key, *members)
|
113
|
-
serialize(members.unshift(:SADD, key))
|
114
|
-
end
|
115
|
-
|
116
|
-
def sunion(*keys)
|
117
|
-
serialize(keys.unshift(:SUNION))
|
118
|
-
end
|
119
|
-
|
120
|
-
# ------------------ Sorted Sets -----------------
|
121
|
-
|
122
|
-
def zadd(key, *args)
|
123
|
-
serialize(args.unshift(:ZADD, key))
|
124
|
-
end
|
125
|
-
|
126
|
-
# @todo Support optional args (WITHSCORES/LIMIT)
|
127
|
-
def zrangebyscore(key, min, max)
|
128
|
-
serialize([:ZRANGEBYSCORE, key, min, max])
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
|
133
|
-
def serialize(command)
|
134
|
-
Protocol.build_command(command)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|