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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1cabed5b3d53ceb51ba113cffb2ace9bab46a1eacefc159531fc24723598c29
4
- data.tar.gz: 566ea90f81848a6c78bb468e351e0c61ddbd01c82d76f9855dbed69ef0016cfc
3
+ metadata.gz: 22aaffd6780592acb9c8150fc63d2ed746b5ec32b23ee53ca423673b3deabe7c
4
+ data.tar.gz: bc1ec498a13ab889d43b47a94b8d95edb39787c962a6b8712cdd8d51e2485501
5
5
  SHA512:
6
- metadata.gz: d2cd6cddf7bf21fc8b71b86ed6739bf9799378a264f27ccb867181e90d298f0357569070080737106674808b738e17b317ef1fb5c1a23c00f47cc2bde86324dd
7
- data.tar.gz: 32cbe030112f49d1fd498804b4756c1108fc3d985bafdcb249507d23b1c4e17372925d0a05e52e55bf67a110bada60f863ca838135f2bdb0d48afc4cccdb02fd
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.2.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"
@@ -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(connection_limit: nil)
143
- Pool.new(connection_limit) do
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 connected?
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)
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module Redis
23
- VERSION = "0.4.1"
23
+ VERSION = "0.4.2"
24
24
  end
25
25
  end
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.1
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: 2019-10-09 00:00:00.000000000 Z
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.2.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.2.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.4
225
+ rubygems_version: 3.0.6
213
226
  signing_key:
214
227
  specification_version: 4
215
228
  summary: A Redis client library.
@@ -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