async-redis 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/async-redis.gemspec +2 -1
- data/lib/async/redis/client.rb +3 -3
- data/lib/async/redis/protocol/resp2.rb +9 -1
- data/lib/async/redis/version.rb +1 -1
- metadata +19 -6
- data/lib/async/redis/pool.rb +0 -135
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22aaffd6780592acb9c8150fc63d2ed746b5ec32b23ee53ca423673b3deabe7c
|
4
|
+
data.tar.gz: bc1ec498a13ab889d43b47a94b8d95edb39787c962a6b8712cdd8d51e2485501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73f977381ba86c9d5a5267dda69911b13d864de691e15e8131765507bf6c025eb751b7542eda876c1bbd0cbc55cd2aab9ec5603e14df1d8471805d41265e4a0f
|
7
|
+
data.tar.gz: d69e6dd696d9f519e524a425cf811ca43392266733ffdca4512eaaa090b7466e840348a81e894aa93412e9ba1f51816df0910280fd9a3145f1937a2e341f7a6a
|
data/async-redis.gemspec
CHANGED
@@ -19,8 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_dependency("async", "~> 1.8")
|
21
21
|
spec.add_dependency("async-io", "~> 1.10")
|
22
|
+
spec.add_dependency("async-pool", "~> 0.2")
|
22
23
|
|
23
|
-
spec.add_dependency("protocol-redis", "~> 0.
|
24
|
+
spec.add_dependency("protocol-redis", "~> 0.3.0")
|
24
25
|
|
25
26
|
spec.add_development_dependency "async-rspec", "~> 1.1"
|
26
27
|
spec.add_development_dependency "redis"
|
data/lib/async/redis/client.rb
CHANGED
@@ -18,7 +18,6 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
require_relative 'pool'
|
22
21
|
require_relative 'context/pipeline'
|
23
22
|
require_relative 'context/transaction'
|
24
23
|
require_relative 'context/subscribe'
|
@@ -27,6 +26,7 @@ require_relative 'protocol/resp2'
|
|
27
26
|
|
28
27
|
require 'async/io'
|
29
28
|
require 'async/io/stream'
|
29
|
+
require 'async/pool/controller'
|
30
30
|
|
31
31
|
require 'protocol/redis/methods'
|
32
32
|
|
@@ -139,8 +139,8 @@ module Async
|
|
139
139
|
|
140
140
|
protected
|
141
141
|
|
142
|
-
def connect(
|
143
|
-
Pool.
|
142
|
+
def connect(**options)
|
143
|
+
Async::Pool::Controller.wrap(**options) do
|
144
144
|
peer = @endpoint.connect
|
145
145
|
|
146
146
|
peer.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
@@ -25,9 +25,17 @@ module Async
|
|
25
25
|
module Protocol
|
26
26
|
module RESP2
|
27
27
|
class Connection < ::Protocol::Redis::Connection
|
28
|
-
def
|
28
|
+
def concurrency
|
29
|
+
1
|
30
|
+
end
|
31
|
+
|
32
|
+
def viable?
|
29
33
|
@stream.connected?
|
30
34
|
end
|
35
|
+
|
36
|
+
def reusable?
|
37
|
+
!@stream.closed?
|
38
|
+
end
|
31
39
|
end
|
32
40
|
|
33
41
|
def self.client(stream)
|
data/lib/async/redis/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: async
|
@@ -39,20 +39,34 @@ dependencies:
|
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '1.10'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: async-pool
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0.2'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0.2'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: protocol-redis
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
45
59
|
requirements:
|
46
60
|
- - "~>"
|
47
61
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.
|
62
|
+
version: 0.3.0
|
49
63
|
type: :runtime
|
50
64
|
prerelease: false
|
51
65
|
version_requirements: !ruby/object:Gem::Requirement
|
52
66
|
requirements:
|
53
67
|
- - "~>"
|
54
68
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
69
|
+
version: 0.3.0
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: async-rspec
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -188,7 +202,6 @@ files:
|
|
188
202
|
- lib/async/redis/context/subscribe.rb
|
189
203
|
- lib/async/redis/context/transaction.rb
|
190
204
|
- lib/async/redis/key.rb
|
191
|
-
- lib/async/redis/pool.rb
|
192
205
|
- lib/async/redis/protocol/resp2.rb
|
193
206
|
- lib/async/redis/version.rb
|
194
207
|
homepage: https://github.com/socketry/async-redis
|
@@ -209,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
222
|
- !ruby/object:Gem::Version
|
210
223
|
version: '0'
|
211
224
|
requirements: []
|
212
|
-
rubygems_version: 3.0.
|
225
|
+
rubygems_version: 3.0.6
|
213
226
|
signing_key:
|
214
227
|
specification_version: 4
|
215
228
|
summary: A Redis client library.
|
data/lib/async/redis/pool.rb
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'async/notification'
|
22
|
-
|
23
|
-
module Async
|
24
|
-
module Redis
|
25
|
-
# It might make sense to add support for pipelining https://redis.io/topics/pipelining
|
26
|
-
# We should be able to wrap the protocol so that write_request and read_response happen in lockstep.
|
27
|
-
# The only problem would be blocking operations. It might also be confusing if order of operations affects commands.
|
28
|
-
class Pool
|
29
|
-
def initialize(limit = nil, &block)
|
30
|
-
@resources = []
|
31
|
-
@available = Async::Notification.new
|
32
|
-
|
33
|
-
@limit = limit
|
34
|
-
@active = 0
|
35
|
-
|
36
|
-
@constructor = block
|
37
|
-
end
|
38
|
-
|
39
|
-
attr :resources
|
40
|
-
|
41
|
-
def empty?
|
42
|
-
@resources.empty?
|
43
|
-
end
|
44
|
-
|
45
|
-
def acquire
|
46
|
-
resource = wait_for_resource
|
47
|
-
|
48
|
-
return resource unless block_given?
|
49
|
-
|
50
|
-
begin
|
51
|
-
yield resource
|
52
|
-
ensure
|
53
|
-
release(resource)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Make the resource resources and let waiting tasks know that there is something resources.
|
58
|
-
def release(resource)
|
59
|
-
# A resource that is not good should also not be reusable.
|
60
|
-
unless resource.closed?
|
61
|
-
reuse(resource)
|
62
|
-
else
|
63
|
-
retire(resource)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def close
|
68
|
-
@resources.each(&:close)
|
69
|
-
@resources.clear
|
70
|
-
|
71
|
-
@active = 0
|
72
|
-
end
|
73
|
-
|
74
|
-
def to_s
|
75
|
-
"\#<#{self.class} resources=#{resources.size} limit=#{@limit}>"
|
76
|
-
end
|
77
|
-
|
78
|
-
protected
|
79
|
-
|
80
|
-
def reuse(resource)
|
81
|
-
Async.logger.debug(self) {"Reuse #{resource}"}
|
82
|
-
|
83
|
-
@resources << resource
|
84
|
-
|
85
|
-
@available.signal
|
86
|
-
end
|
87
|
-
|
88
|
-
def retire(resource)
|
89
|
-
Async.logger.debug(self) {"Retire #{resource}"}
|
90
|
-
|
91
|
-
@active -= 1
|
92
|
-
|
93
|
-
resource.close
|
94
|
-
|
95
|
-
@available.signal
|
96
|
-
end
|
97
|
-
|
98
|
-
def wait_for_resource
|
99
|
-
# If we fail to create a resource (below), we will end up waiting for one to become resources.
|
100
|
-
until resource = available_resource
|
101
|
-
@available.wait
|
102
|
-
end
|
103
|
-
|
104
|
-
Async.logger.debug(self) {"Wait for resource #{resource}"}
|
105
|
-
|
106
|
-
return resource
|
107
|
-
end
|
108
|
-
|
109
|
-
def create
|
110
|
-
# This might return nil, which means creating the resource failed.
|
111
|
-
return @constructor.call
|
112
|
-
end
|
113
|
-
|
114
|
-
def available_resource
|
115
|
-
while resource = @resources.pop
|
116
|
-
if resource.connected?
|
117
|
-
return resource
|
118
|
-
else
|
119
|
-
retire(resource)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
if !@limit or @active < @limit
|
124
|
-
Async.logger.debug(self) {"No resources resources, allocating new one..."}
|
125
|
-
|
126
|
-
@active += 1
|
127
|
-
|
128
|
-
return create
|
129
|
-
end
|
130
|
-
|
131
|
-
return nil
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|