redis 5.0.0.beta3 → 5.0.0.beta4

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: a8bcabf5f725061ad3fba18ed42eed7ce26788cf41b78f2091e6033530e124e0
4
- data.tar.gz: 6b22ffde2abc13f944641c17972013cb4084dd91989127d6a3f9232b1b21ec5d
3
+ metadata.gz: 94568e707734a9e2f7c90aa599174444c27313d30e877b74f5989d50b60e31cf
4
+ data.tar.gz: cf1ce567caae9928ba4d9902b26621e83a44ee8c4989420df9e5616684970cfb
5
5
  SHA512:
6
- metadata.gz: 21141ffa7c06d44599ba93097ec2000abd6325afe2e7175a15f0c0dddfae7b2a120b8acd5f14937f1c58fb971e2fd04603721388a53f6ea42b66031f8b1f9058
7
- data.tar.gz: 1b0996205f973aba8c7db27726eacbe2a03e4339d0444eee80e68958a5226b70349437a518a5f8d0a7b419106e9c9ae546d349dbf7c639ca9a51a721ca96a51c
6
+ metadata.gz: 36d2cf7667a6c94b575e0e20074e088982c2fafc070ef42885b00207298d2814b5045e1eeae6cd12d971e0054fa86181d03f3ad0a2b044cfd4e40c4ac9c93852
7
+ data.tar.gz: 1208702dde8518adf21a497b75613824167526d3ddd1c99dda6ae06a319081b7d3473d83183cc76623008043e17c3bc206da1b86d89e9108c004c6fbadc34994
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Unreleased
2
2
 
3
+ # 5.0.0.beta4
4
+
5
+ - Allow to call `subscribe`, `unsubscribe`, `psubscribe` and `punsubscribe` from a subscribed client. See #1131.
6
+ - Fix `redis-clustering` gem to specify the dependency on `redis`
7
+
3
8
  # 5.0.0.beta3
4
9
 
5
10
  - Use `MD5` for hashing server nodes in `Redis::Distributed`. This should improve keys distribution among servers. See #1089.
@@ -14,50 +14,34 @@ class Redis
14
14
 
15
15
  # Listen for messages published to the given channels.
16
16
  def subscribe(*channels, &block)
17
- synchronize do |_client|
18
- _subscription(:subscribe, 0, channels, block)
19
- end
17
+ _subscription(:subscribe, 0, channels, block)
20
18
  end
21
19
 
22
20
  # Listen for messages published to the given channels. Throw a timeout error
23
21
  # if there is no messages for a timeout period.
24
22
  def subscribe_with_timeout(timeout, *channels, &block)
25
- synchronize do |_client|
26
- _subscription(:subscribe_with_timeout, timeout, channels, block)
27
- end
23
+ _subscription(:subscribe_with_timeout, timeout, channels, block)
28
24
  end
29
25
 
30
26
  # Stop listening for messages posted to the given channels.
31
27
  def unsubscribe(*channels)
32
- raise "Can't unsubscribe if not subscribed." unless subscribed?
33
-
34
- synchronize do |_client|
35
- _subscription(:unsubscribe, 0, channels, nil)
36
- end
28
+ _subscription(:unsubscribe, 0, channels, nil)
37
29
  end
38
30
 
39
31
  # Listen for messages published to channels matching the given patterns.
40
32
  def psubscribe(*channels, &block)
41
- synchronize do |_client|
42
- _subscription(:psubscribe, 0, channels, block)
43
- end
33
+ _subscription(:psubscribe, 0, channels, block)
44
34
  end
45
35
 
46
36
  # Listen for messages published to channels matching the given patterns.
47
37
  # Throw a timeout error if there is no messages for a timeout period.
48
38
  def psubscribe_with_timeout(timeout, *channels, &block)
49
- synchronize do |_client|
50
- _subscription(:psubscribe_with_timeout, timeout, channels, block)
51
- end
39
+ _subscription(:psubscribe_with_timeout, timeout, channels, block)
52
40
  end
53
41
 
54
42
  # Stop listening for messages posted to channels matching the given patterns.
55
43
  def punsubscribe(*channels)
56
- raise "Can't unsubscribe if not subscribed." unless subscribed?
57
-
58
- synchronize do |_client|
59
- _subscription(:punsubscribe, 0, channels, nil)
60
- end
44
+ _subscription(:punsubscribe, 0, channels, nil)
61
45
  end
62
46
 
63
47
  # Inspect the state of the Pub/Sub subsystem.
@@ -904,7 +904,7 @@ class Redis
904
904
 
905
905
  # Stop listening for messages posted to the given channels.
906
906
  def unsubscribe(*channels)
907
- raise "Can't unsubscribe if not subscribed." unless subscribed?
907
+ raise SubscriptionError, "Can't unsubscribe if not subscribed." unless subscribed?
908
908
 
909
909
  @subscribed_node.unsubscribe(*channels)
910
910
  end
data/lib/redis/errors.rb CHANGED
@@ -52,4 +52,7 @@ class Redis
52
52
  # Raised when client options are invalid.
53
53
  class InvalidClientOptionError < BaseError
54
54
  end
55
+
56
+ class SubscriptionError < BaseError
57
+ end
55
58
  end
@@ -4,10 +4,13 @@ class Redis
4
4
  class SubscribedClient
5
5
  def initialize(client)
6
6
  @client = client
7
+ @write_monitor = Monitor.new
7
8
  end
8
9
 
9
10
  def call_v(command)
10
- @client.call_v(command)
11
+ @write_monitor.synchronize do
12
+ @client.call_v(command)
13
+ end
11
14
  end
12
15
 
13
16
  def subscribe(*channels, &block)
@@ -43,14 +46,16 @@ class Redis
43
46
  def subscription(start, stop, channels, block, timeout = 0)
44
47
  sub = Subscription.new(&block)
45
48
 
46
- @client.call_v([start, *channels])
49
+ call_v([start, *channels])
47
50
  while event = @client.next_event(timeout)
48
51
  if event.is_a?(::RedisClient::CommandError)
49
52
  raise Client::ERROR_MAPPING.fetch(event.class), event.message
50
53
  end
51
54
 
52
55
  type, *rest = event
53
- sub.callbacks[type].call(*rest)
56
+ if callback = sub.callbacks[type]
57
+ callback.call(*rest)
58
+ end
54
59
  break if type == stop && rest.last == 0
55
60
  end
56
61
  # No need to unsubscribe here. The real client closes the connection
@@ -62,10 +67,7 @@ class Redis
62
67
  attr :callbacks
63
68
 
64
69
  def initialize
65
- @callbacks = Hash.new do |hash, key|
66
- hash[key] = ->(*_) {}
67
- end
68
-
70
+ @callbacks = {}
69
71
  yield(self)
70
72
  end
71
73
 
data/lib/redis/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Redis
4
- VERSION = '5.0.0.beta3'
4
+ VERSION = '5.0.0.beta4'
5
5
  end
data/lib/redis.rb CHANGED
@@ -165,19 +165,27 @@ class Redis
165
165
  end
166
166
 
167
167
  def _subscription(method, timeout, channels, block)
168
- if @subscription_client
169
- return @subscription_client.call_v([method] + channels)
170
- end
168
+ if block
169
+ if @subscription_client
170
+ raise SubscriptionError, "This client is already subscribed"
171
+ end
171
172
 
172
- begin
173
- @subscription_client = SubscribedClient.new(@client.pubsub)
174
- if timeout > 0
175
- @subscription_client.send(method, timeout, *channels, &block)
176
- else
177
- @subscription_client.send(method, *channels, &block)
173
+ begin
174
+ @subscription_client = SubscribedClient.new(@client.pubsub)
175
+ if timeout > 0
176
+ @subscription_client.send(method, timeout, *channels, &block)
177
+ else
178
+ @subscription_client.send(method, *channels, &block)
179
+ end
180
+ ensure
181
+ @subscription_client = nil
178
182
  end
179
- ensure
180
- @subscription_client = nil
183
+ else
184
+ unless @subscription_client
185
+ raise SubscriptionError, "This client is not subscribed"
186
+ end
187
+
188
+ @subscription_client.call_v([method].concat(channels))
181
189
  end
182
190
  end
183
191
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.beta3
4
+ version: 5.0.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -16,7 +16,7 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2022-08-18 00:00:00.000000000 Z
19
+ date: 2022-08-19 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: redis-client
@@ -75,9 +75,9 @@ licenses:
75
75
  metadata:
76
76
  bug_tracker_uri: https://github.com/redis/redis-rb/issues
77
77
  changelog_uri: https://github.com/redis/redis-rb/blob/master/CHANGELOG.md
78
- documentation_uri: https://www.rubydoc.info/gems/redis/5.0.0.beta3
78
+ documentation_uri: https://www.rubydoc.info/gems/redis/5.0.0.beta4
79
79
  homepage_uri: https://github.com/redis/redis-rb
80
- source_code_uri: https://github.com/redis/redis-rb/tree/v5.0.0.beta3
80
+ source_code_uri: https://github.com/redis/redis-rb/tree/v5.0.0.beta4
81
81
  post_install_message:
82
82
  rdoc_options: []
83
83
  require_paths: