async-redis 0.10.0 → 0.10.1
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/changes.md +46 -0
- data/lib/async/redis/cluster_client.rb +11 -6
- data/lib/async/redis/endpoint.rb +5 -4
- data/lib/async/redis/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da847e343c291506a20337eec6170867a0e0bf295b713ece60fd7f48928d873f
|
4
|
+
data.tar.gz: 2ea6e2720f556084f57415501a1964c0bb2a93a411a9cb52138dbb8ed141c45b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ac74325525a0dc00b06aaee1fa505566bce74f4806c07f26a8581ac7b20db79f11cbb052d6d598d02b7eec94aae6a142d88da00eb01e4b0a8d72e134ef5a798
|
7
|
+
data.tar.gz: 2b873fd8ee1cfffda74d301265ec9477a34dfe571d30d4c36d195cf39b089c22635bc74c07ade143ca46a5e169d0db226470a6149ce912be3b3da0db96e26b49
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/changes.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# v0.10.0
|
2
|
+
|
3
|
+
## Cluster Client
|
4
|
+
|
5
|
+
`Async::Redis::ClusterClient` is a new class that provides a high-level interface to a Redis Cluster. Due to the way clustering works, it does not provide the same interface as the `Async::Redis::Client` class. Instead, you must request an appropriate client for the key you are working with.
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
endpoints = [
|
9
|
+
Async::Redis::Endpoint.parse("redis://redis-a"),
|
10
|
+
Async::Redis::Endpoint.parse("redis://redis-b"),
|
11
|
+
Async::Redis::Endpoint.parse("redis://redis-c"),
|
12
|
+
]
|
13
|
+
|
14
|
+
cluster_client = Async::Redis::ClusterClient.new(endpoints)
|
15
|
+
|
16
|
+
cluster_client.clients_for("key") do |client|
|
17
|
+
puts client.get("key")
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
## Sentinel Client
|
22
|
+
|
23
|
+
The previous implementation `Async::Redis::SentinelsClient` has been replaced with `Async::Redis::SentinelClient`. This new class uses `Async::Redis::Endpoint` objects to represent the sentinels and the master.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
sentinels = [
|
27
|
+
Async::Redis::Endpoint.parse("redis://redis-sentinel-a"),
|
28
|
+
Async::Redis::Endpoint.parse("redis://redis-sentinel-b"),
|
29
|
+
Async::Redis::Endpoint.parse("redis://redis-sentinel-c"),
|
30
|
+
]
|
31
|
+
|
32
|
+
master_client = Async::Redis::SentinelClient.new(sentinels)
|
33
|
+
slave_client = Async::Redis::SentinelClient.new(sentinels, role: :slave)
|
34
|
+
|
35
|
+
master_client.session do |session|
|
36
|
+
session.set("key", "value")
|
37
|
+
end
|
38
|
+
|
39
|
+
slave_client.session do |session|
|
40
|
+
puts session.get("key")
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
## Integration Tests
|
45
|
+
|
46
|
+
Integration tests for Redis Cluster and Sentinel have been added, using `docker-compose` to start the required services and run the tests. These tests are not part of the default test suite and must be run separately. See the documentation in the `sentinel/` and `cluster/` directories for more information.
|
@@ -13,6 +13,9 @@ module Async
|
|
13
13
|
class ReloadError < StandardError
|
14
14
|
end
|
15
15
|
|
16
|
+
class SlotError < StandardError
|
17
|
+
end
|
18
|
+
|
16
19
|
Node = Struct.new(:id, :endpoint, :role, :health, :client)
|
17
20
|
|
18
21
|
class RangeMap
|
@@ -84,9 +87,11 @@ module Async
|
|
84
87
|
reload_cluster!
|
85
88
|
end
|
86
89
|
|
87
|
-
nodes = @shards.find(slot)
|
88
|
-
|
89
|
-
|
90
|
+
if nodes = @shards.find(slot)
|
91
|
+
nodes = nodes.select{|node| node.role == role}
|
92
|
+
else
|
93
|
+
raise SlotError, "No nodes found for slot #{slot}"
|
94
|
+
end
|
90
95
|
|
91
96
|
if node = nodes.sample
|
92
97
|
return (node.client ||= Client.new(node.endpoint))
|
@@ -106,7 +111,7 @@ module Async
|
|
106
111
|
shard = shard.each_slice(2).to_h
|
107
112
|
|
108
113
|
slots = shard['slots']
|
109
|
-
range = Range.new(*slots
|
114
|
+
range = Range.new(*slots)
|
110
115
|
|
111
116
|
nodes = shard['nodes'].map do |node|
|
112
117
|
node = node.each_slice(2).to_h
|
@@ -179,10 +184,10 @@ module Async
|
|
179
184
|
return sum
|
180
185
|
end
|
181
186
|
|
182
|
-
HASH_SLOTS = 16_384
|
183
|
-
|
184
187
|
public
|
185
188
|
|
189
|
+
HASH_SLOTS = 16_384
|
190
|
+
|
186
191
|
# Return Redis::Client for a given key.
|
187
192
|
# Modified from https://github.com/antirez/redis-rb-cluster/blob/master/cluster.rb#L104-L117
|
188
193
|
def slot_for(key)
|
data/lib/async/redis/endpoint.rb
CHANGED
@@ -44,7 +44,7 @@ module Async
|
|
44
44
|
#
|
45
45
|
# @parameter scheme [String] The scheme to use, e.g. "redis" or "rediss".
|
46
46
|
# @parameter hostname [String] The hostname to connect to (or bind to).
|
47
|
-
# @parameter
|
47
|
+
# @parameter options [Hash] Additional options, passed to {#initialize}.
|
48
48
|
def self.for(scheme, hostname, credentials: nil, port: nil, database: nil, **options)
|
49
49
|
uri_klass = SCHEMES.fetch(scheme.downcase) do
|
50
50
|
raise ArgumentError, "Unsupported scheme: #{scheme.inspect}"
|
@@ -74,9 +74,10 @@ module Async
|
|
74
74
|
#
|
75
75
|
# @parameter url [URI] The URL to connect to.
|
76
76
|
# @parameter endpoint [Endpoint] The underlying endpoint to use.
|
77
|
-
# @
|
78
|
-
# @
|
79
|
-
# @
|
77
|
+
# @option scheme [String] The scheme to use, e.g. "redis" or "rediss".
|
78
|
+
# @option hostname [String] The hostname to connect to (or bind to), overrides the URL hostname (used for SNI).
|
79
|
+
# @option port [Integer] The port to bind to, overrides the URL port.
|
80
|
+
# @option ssl_context [OpenSSL::SSL::SSLContext] The SSL context to use for secure connections.
|
80
81
|
def initialize(url, endpoint = nil, **options)
|
81
82
|
super(**options)
|
82
83
|
|
data/lib/async/redis/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
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.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -48,7 +48,7 @@ cert_chain:
|
|
48
48
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
49
49
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
50
50
|
-----END CERTIFICATE-----
|
51
|
-
date: 2024-08-
|
51
|
+
date: 2024-08-22 00:00:00.000000000 Z
|
52
52
|
dependencies:
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: async
|
@@ -126,6 +126,7 @@ executables: []
|
|
126
126
|
extensions: []
|
127
127
|
extra_rdoc_files: []
|
128
128
|
files:
|
129
|
+
- changes.md
|
129
130
|
- lib/async/redis.rb
|
130
131
|
- lib/async/redis/client.rb
|
131
132
|
- lib/async/redis/cluster_client.rb
|
metadata.gz.sig
CHANGED
Binary file
|