async-redis 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e409b3ef4f0989517bcf877880475280c64b979f63622ab347e030d0185b1e4
4
- data.tar.gz: 74f33ea9534d6fd0337d818475a3addacafa7121bd988be2366aaebc7f1f1e44
3
+ metadata.gz: 7df67fb815da0415518fcc011ff73ee1dce3fc6e5efa499062e53cbd02759330
4
+ data.tar.gz: 263cb0d0e8e6b773c52e6a238363199fa7349649999b5de0be6377c77a7f9af6
5
5
  SHA512:
6
- metadata.gz: 1c71e0975e0559084b767b213462d71489c74f03f58549fc38bda7ee05130a40bdfadd4e5cb784bb8cbf96b1f5b2b4bd00221f6da5c5d5068b36dc6344b5fb0d
7
- data.tar.gz: 8627a5adee5087961d1174d18d0db1e967133cfcdc7d63fb646c157a2b17137ab19dcb528b7c6261ffe789713f3e9fef41b890c83f7fbfaa09528e2718cd1150
6
+ metadata.gz: c4a1c6346b810d497f5af9af1de602231db80dab9e1c500cf20ffd9528c326371ef1f2aad3038d033fcbdd7736765cea411cec0424394d3357f902f218d6c739
7
+ data.tar.gz: a6a3fae1da6a065f4c7c9eaf697b486b6065298ebb1d3ffe18e116d403e4273461e171846770b8ad246d0b0c6310ffc3c2a3ac71e034ecfd79aa9b0371b5d62b
checksums.yaml.gz.sig CHANGED
Binary file
data/context/index.yaml CHANGED
@@ -3,6 +3,8 @@
3
3
  ---
4
4
  description: A Redis client library.
5
5
  metadata:
6
+ bug_tracker_uri: https://github.com/socketry/async-redis/issues
7
+ changelog_uri: https://github.com/socketry/async-redis/blob/main/releases.md
6
8
  documentation_uri: https://socketry.github.io/async-redis/
7
9
  source_code_uri: https://github.com/socketry/async-redis.git
8
10
  files:
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024-2025, by Samuel Williams.
5
- # Copyright, 2025, by Travis Bell.
5
+ # Copyright, 2025-2026, by Travis Bell.
6
6
 
7
7
  require_relative "client"
8
8
  require_relative "cluster_subscription"
@@ -110,37 +110,36 @@ module Async
110
110
  protected
111
111
 
112
112
  def reload_cluster!(endpoints = @endpoints)
113
- @endpoints.each do |endpoint|
114
- client = Client.new(endpoint, **@options)
113
+ @endpoints.each do |cluster_endpoint|
114
+ client = Client.new(cluster_endpoint, **@options)
115
115
 
116
- shards = Async::Redis::RangeMap.new
117
- endpoints = []
118
-
119
- client.call("CLUSTER", "SHARDS").each do |shard|
120
- shard = shard.each_slice(2).to_h
121
-
122
- slots = shard["slots"]
123
- range = Range.new(*slots)
116
+ begin
117
+ shards = Async::Redis::RangeMap.new
124
118
 
125
- nodes = shard["nodes"].map do |node|
126
- node = node.each_slice(2).to_h
127
- endpoint = Endpoint.for(endpoint.scheme, node["endpoint"], port: node["port"])
119
+ client.call("CLUSTER", "SHARDS").each do |shard|
120
+ shard = shard.each_slice(2).to_h
128
121
 
129
- # Collect all endpoints:
130
- endpoints << endpoint
122
+ nodes = shard["nodes"].map do |node|
123
+ node = node.each_slice(2).to_h
124
+ node_endpoint = Endpoint.for(cluster_endpoint.scheme, node["endpoint"], port: node["port"])
125
+
126
+ Node.new(node["id"], node_endpoint, node["role"].to_sym, node["health"].to_sym)
127
+ end
128
+ ranges = shard["slots"].each_slice(2).map do |first_slot, last_slot|
129
+ first_slot..last_slot
130
+ end
131
131
 
132
- Node.new(node["id"], endpoint, node["role"].to_sym, node["health"].to_sym)
132
+ shards.add(ranges, nodes)
133
133
  end
134
134
 
135
- shards.add(range, nodes)
135
+ @shards = shards
136
+
137
+ return true
138
+ rescue Errno::ECONNREFUSED
139
+ next
140
+ ensure
141
+ client.close
136
142
  end
137
-
138
- @shards = shards
139
- # @endpoints = @endpoints | endpoints
140
-
141
- return true
142
- rescue Errno::ECONNREFUSED
143
- next
144
143
  end
145
144
 
146
145
  raise ReloadError, "Failed to reload cluster configuration."
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2025, by Samuel Williams.
4
+ # Copyright, 2025-2026, by Samuel Williams.
5
5
 
6
6
  require "async/limited_queue"
7
7
  require "async/barrier"
@@ -102,7 +102,7 @@ module Async
102
102
  @channels -= channels_for_slot
103
103
 
104
104
  # Check if this shard still has channels
105
- remaining_channels_for_slot = @channels.select {|ch| @cluster_client.slot_for(ch) == slot}
105
+ remaining_channels_for_slot = @channels.select{|ch| @cluster_client.slot_for(ch) == slot}
106
106
 
107
107
  # If no channels left for this shard, close and remove it
108
108
  if remaining_channels_for_slot.empty?
@@ -80,7 +80,7 @@ module Async
80
80
  scheme ||= default_scheme
81
81
  end
82
82
 
83
- scheme ||= options.key?(:ssl_context) ? "rediss" : "redis"
83
+ scheme ||= options[:ssl_context] ? "rediss" : "redis"
84
84
 
85
85
  uri_klass = SCHEMES.fetch(scheme.downcase) do
86
86
  raise ArgumentError, "Unsupported scheme: #{scheme.inspect}"
@@ -2,22 +2,24 @@
2
2
 
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2025, by Samuel Williams.
5
+ # Copyright, 2026, by Travis Bell.
5
6
 
6
7
  module Async
7
8
  module Redis
8
- # A map that stores ranges and their associated values for efficient lookup.
9
+ # A map that associates one or more ranges with a value for efficient lookup.
9
10
  class RangeMap
10
11
  # Initialize a new RangeMap.
11
12
  def initialize
12
- @ranges = []
13
+ @entries = []
13
14
  end
14
15
 
15
- # Add a range-value pair to the map.
16
- # @parameter range [Range] The range to map.
17
- # @parameter value [Object] The value to associate with the range.
16
+ # Add one or more ranges associated with a value to the map.
17
+ # @parameter ranges [Range | Array(Range)] The ranges to map.
18
+ # @parameter value [Object] The value to associate with the ranges.
18
19
  # @returns [Object] The added value.
19
- def add(range, value)
20
- @ranges << [range, value]
20
+ def add(ranges, value)
21
+ ranges = [ranges] if ranges.is_a?(Range)
22
+ @entries << [ranges, value]
21
23
  return value
22
24
  end
23
25
 
@@ -26,8 +28,8 @@ module Async
26
28
  # @yields {...} Block called if no range contains the key.
27
29
  # @returns [Object] The value if found, result of block if given, or nil.
28
30
  def find(key)
29
- @ranges.each do |range, value|
30
- return value if range.include?(key)
31
+ @entries.each do |ranges, value|
32
+ return value if ranges.any?{|range| range.include?(key)}
31
33
  end
32
34
  if block_given?
33
35
  return yield
@@ -35,11 +37,11 @@ module Async
35
37
  return nil
36
38
  end
37
39
 
38
- # Iterate over all values in the map.
40
+ # Iterate over each mapped value.
39
41
  # @yields {|value| ...} Block called for each value.
40
- # @parameter value [Object] The value from the range-value pair.
42
+ # @parameter value [Object] The value associated with one or more ranges.
41
43
  def each
42
- @ranges.each do |range, value|
44
+ @entries.each do |_, value|
43
45
  yield value
44
46
  end
45
47
  end
@@ -47,14 +49,14 @@ module Async
47
49
  # Get a random value from the map.
48
50
  # @returns [Object] A randomly selected value, or nil if map is empty.
49
51
  def sample
50
- return nil if @ranges.empty?
51
- range, value = @ranges.sample
52
+ return nil if @entries.empty?
53
+ _, value = @entries.sample
52
54
  return value
53
55
  end
54
56
 
55
57
  # Clear all ranges from the map.
56
58
  def clear
57
- @ranges.clear
59
+ @entries.clear
58
60
  end
59
61
  end
60
62
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module Redis
8
- VERSION = "0.13.0"
8
+ VERSION = "0.14.0"
9
9
  end
10
10
  end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2018-2025, by Samuel Williams.
3
+ Copyright, 2018-2026, by Samuel Williams.
4
4
  Copyright, 2018, by Huba Nagy.
5
5
  Copyright, 2019-2020, by David Ortiz.
6
6
  Copyright, 2019, by Pierre Montelle.
@@ -13,7 +13,7 @@ Copyright, 2021, by Troex Nevelin.
13
13
  Copyright, 2022, by Tim Willard.
14
14
  Copyright, 2022, by Gleb Sinyavskiy.
15
15
  Copyright, 2024-2025, by Joan Lledó.
16
- Copyright, 2025, by Travis Bell.
16
+ Copyright, 2025-2026, by Travis Bell.
17
17
 
18
18
  Permission is hereby granted, free of charge, to any person obtaining a copy
19
19
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -60,11 +60,27 @@ Please see the [project releases](https://socketry.github.io/async-redis/release
60
60
 
61
61
  We welcome contributions to this project.
62
62
 
63
- 1. Fork it.
63
+ 1. Fork the repository.
64
64
  2. Create your feature branch (`git checkout -b my-new-feature`).
65
- 3. Commit your changes (`git commit -am 'Add some feature'`).
65
+ 3. Commit your changes (`git commit -am 'Add some feature.'`).
66
66
  4. Push to the branch (`git push origin my-new-feature`).
67
- 5. Create new Pull Request.
67
+ 5. Create a new pull request.
68
+
69
+ ### Running Tests
70
+
71
+ To run the test suite:
72
+
73
+ ``` shell
74
+ bundle exec sus
75
+ ```
76
+
77
+ ### Making Releases
78
+
79
+ To make a new release:
80
+
81
+ ``` shell
82
+ bundle exec bake gem:release:patch # or minor or major
83
+ ```
68
84
 
69
85
  ### Developer Certificate of Origin
70
86
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - Huba Nagy
9
9
  - David Ortiz
10
10
  - Joan Lledó
11
+ - Travis Bell
11
12
  - Gleb Sinyavskiy
12
13
  - Mikael Henriksson
13
- - Travis Bell
14
14
  - Troex Nevelin
15
15
  - Alex Matchneer
16
16
  - Jeremy Jung
@@ -156,6 +156,8 @@ homepage: https://github.com/socketry/async-redis
156
156
  licenses:
157
157
  - MIT
158
158
  metadata:
159
+ bug_tracker_uri: https://github.com/socketry/async-redis/issues
160
+ changelog_uri: https://github.com/socketry/async-redis/blob/main/releases.md
159
161
  documentation_uri: https://socketry.github.io/async-redis/
160
162
  source_code_uri: https://github.com/socketry/async-redis.git
161
163
  rdoc_options: []
@@ -165,14 +167,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
167
  requirements:
166
168
  - - ">="
167
169
  - !ruby/object:Gem::Version
168
- version: '3.2'
170
+ version: '3.3'
169
171
  required_rubygems_version: !ruby/object:Gem::Requirement
170
172
  requirements:
171
173
  - - ">="
172
174
  - !ruby/object:Gem::Version
173
175
  version: '0'
174
176
  requirements: []
175
- rubygems_version: 3.6.9
177
+ rubygems_version: 4.0.10
176
178
  specification_version: 4
177
179
  summary: A Redis client library.
178
180
  test_files: []
metadata.gz.sig CHANGED
Binary file