oxblood 0.1.0.dev4 → 0.1.0.dev5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/oxblood/pipeline.rb +20 -5
- data/lib/oxblood/pool.rb +25 -0
- data/lib/oxblood/session.rb +10 -0
- data/lib/oxblood/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b3e70584c6264f36457da12558ba76dcabc4b19
|
4
|
+
data.tar.gz: 06a8d8e83f0e9d9a68790126fb1324023cd86c08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36e9a9993f99b8fc11ebb7ee0208964c7eaedf08ce300f3b0061844dfe3d080e25d0d7b66353564b9a73c9c3af624b9e3f18773cbfb2c2ff0fac067b93e7a4fb
|
7
|
+
data.tar.gz: b8612141ca6b893edc340ce5247cf7f2a2b3429baf1b0ccd4688deb1fe2c77fd586910dba1fcb5658a6450c18472b7ba5f4efb2f50e4d8278846c8f22f66e6f7
|
data/lib/oxblood/pipeline.rb
CHANGED
@@ -1,18 +1,33 @@
|
|
1
|
+
require 'oxblood/session'
|
2
|
+
|
1
3
|
module Oxblood
|
4
|
+
# Redis pipeling class. Commands won't be send until {#sync} is called.
|
5
|
+
# @see http://redis.io/topics/pipelining#redis-pipelining
|
6
|
+
#
|
7
|
+
# @example Basic workflow
|
8
|
+
# pipeline = Pipeline.new(connection)
|
9
|
+
# pipeline.echo('ping')
|
10
|
+
# pipeline.ping
|
11
|
+
# pipeline.echo('!')
|
12
|
+
# pipeline.sync # => ["ping", "PONG", "!"]
|
2
13
|
class Pipeline < Session
|
3
14
|
def initialize(connection)
|
4
15
|
super
|
5
16
|
@commands = Array.new
|
6
17
|
end
|
7
18
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
19
|
+
# Sends all commands at once and reads responses
|
20
|
+
# @return [Array] of responses
|
12
21
|
def sync
|
13
|
-
serialized_commands = @commands.map { |c| serialize(
|
22
|
+
serialized_commands = @commands.map { |c| serialize(*c) }
|
14
23
|
@connection.write(serialized_commands.join)
|
15
24
|
@connection.read_responses(@commands.size)
|
16
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def run(*command)
|
30
|
+
@commands << command
|
31
|
+
end
|
17
32
|
end
|
18
33
|
end
|
data/lib/oxblood/pool.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'connection_pool'
|
2
2
|
require 'oxblood/session'
|
3
3
|
require 'oxblood/pipeline'
|
4
|
+
require 'oxblood/connection'
|
4
5
|
|
5
6
|
module Oxblood
|
7
|
+
# Connection pool to Redis server
|
6
8
|
class Pool
|
7
9
|
# Initialize connection pool
|
8
10
|
#
|
@@ -20,6 +22,17 @@ module Oxblood
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
25
|
+
# Run commands on a connection from pool.
|
26
|
+
# Connection is wrapped to the {Session}.
|
27
|
+
# @yield [session] provide {Session} to a block
|
28
|
+
# @yieldreturn response from the last executed operation
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# pool = Oxblood::Pool.new(size: 8)
|
32
|
+
# pool.with do |session|
|
33
|
+
# session.set('hello', 'world')
|
34
|
+
# session.get('hello')
|
35
|
+
# end # => 'world'
|
23
36
|
def with
|
24
37
|
conn = @pool.checkout
|
25
38
|
yield Session.new(conn)
|
@@ -27,6 +40,18 @@ module Oxblood
|
|
27
40
|
@pool.checkin if conn
|
28
41
|
end
|
29
42
|
|
43
|
+
# Run commands on a connection from pool. Connection is wrapped to
|
44
|
+
# the {Pipeline}. {Pipeline#sync} operation will be executed automatically
|
45
|
+
# at the end of a block.
|
46
|
+
# @yield [pipeline] provide {Pipeline} to a block
|
47
|
+
# @yieldreturn [Array] responses from all executed operations
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# pool = Oxblood::Pool.new(size: 8)
|
51
|
+
# pool.pipelined do |pipeline|
|
52
|
+
# pipeline.set('hello', 'world')
|
53
|
+
# pipeline.get('hello')
|
54
|
+
# end # => ['OK', 'world']
|
30
55
|
def pipelined
|
31
56
|
conn = @pool.checkout
|
32
57
|
pipeline = Pipeline.new(conn)
|
data/lib/oxblood/session.rb
CHANGED
@@ -192,6 +192,16 @@ module Oxblood
|
|
192
192
|
run(:AUTH, password)
|
193
193
|
end
|
194
194
|
|
195
|
+
# Echo the given string
|
196
|
+
# @see http://redis.io/commands/echo
|
197
|
+
#
|
198
|
+
# @param [String] message
|
199
|
+
#
|
200
|
+
# @return [String] given string
|
201
|
+
def echo(message)
|
202
|
+
run(:ECHO, message)
|
203
|
+
end
|
204
|
+
|
195
205
|
# Like {#auth}, except that if error returned, raises it.
|
196
206
|
#
|
197
207
|
# @param [String] password
|
data/lib/oxblood/version.rb
CHANGED
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.dev5
|
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-07-
|
11
|
+
date: 2016-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|