async-redis 0.10.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/redis/client.rb +17 -10
- data/lib/async/redis/cluster_client.rb +10 -11
- data/lib/async/redis/context/generic.rb +1 -1
- data/lib/async/redis/context/pipeline.rb +1 -1
- data/lib/async/redis/context/subscribe.rb +13 -5
- data/lib/async/redis/context/transaction.rb +5 -5
- data/lib/async/redis/endpoint.rb +9 -9
- data/lib/async/redis/protocol/authenticated.rb +1 -1
- data/lib/async/redis/protocol/resp2.rb +1 -1
- data/lib/async/redis/protocol/selected.rb +1 -1
- data/lib/async/redis/sentinel_client.rb +19 -12
- data/lib/async/redis/version.rb +1 -1
- data/lib/async/redis.rb +5 -5
- data/license.md +1 -0
- data.tar.gz.sig +0 -0
- metadata +4 -3
- 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: c93d4c6fc6b638cb339e1593a9f459041d886a2a6bebb1d195fb168af3076ecd
|
4
|
+
data.tar.gz: 10e62c4f23691e541cb9b3430f5b7333c851f712308926d8249e5062a88eff59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1f44727870268dc6916e45addea89230d11af79d6d4546e1bd43140c534744b61acf5c6ee9bd301e7c9bb4ef69862b859556cccaac7e00af04ab5ce88552eca
|
7
|
+
data.tar.gz: 66d6d26209c7de1d87cd5095685c4f1fed235409d0e41966e1c55fc10c5e1e1a7469b734b144b654b072b18b1933bcf2c2e7b8ee1f7204f4f3a18b9af43ec3e6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/async/redis/client.rb
CHANGED
@@ -7,16 +7,16 @@
|
|
7
7
|
# Copyright, 2019, by David Ortiz.
|
8
8
|
# Copyright, 2020, by Salim Semaoune.
|
9
9
|
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
13
|
-
require_relative
|
10
|
+
require_relative "context/pipeline"
|
11
|
+
require_relative "context/transaction"
|
12
|
+
require_relative "context/subscribe"
|
13
|
+
require_relative "endpoint"
|
14
14
|
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
15
|
+
require "io/endpoint/host_endpoint"
|
16
|
+
require "async/pool/controller"
|
17
|
+
require "protocol/redis/methods"
|
18
18
|
|
19
|
-
require
|
19
|
+
require "io/stream"
|
20
20
|
|
21
21
|
module Async
|
22
22
|
module Redis
|
@@ -89,7 +89,7 @@ module Async
|
|
89
89
|
@endpoint = endpoint
|
90
90
|
@protocol = protocol
|
91
91
|
|
92
|
-
@pool =
|
92
|
+
@pool = make_pool(**options)
|
93
93
|
end
|
94
94
|
|
95
95
|
attr :endpoint
|
@@ -113,7 +113,14 @@ module Async
|
|
113
113
|
|
114
114
|
protected
|
115
115
|
|
116
|
-
def
|
116
|
+
def assign_default_tags(tags)
|
117
|
+
tags[:endpoint] = @endpoint.to_s
|
118
|
+
tags[:protocol] = @protocol.to_s
|
119
|
+
end
|
120
|
+
|
121
|
+
def make_pool(**options)
|
122
|
+
self.assign_default_tags(options[:tags] ||= {})
|
123
|
+
|
117
124
|
Async::Pool::Controller.wrap(**options) do
|
118
125
|
peer = @endpoint.connect
|
119
126
|
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright,
|
5
|
-
# Copyright, 2023-2024, by Samuel Williams.
|
4
|
+
# Copyright, 2024, by Samuel Williams.
|
6
5
|
|
7
|
-
require_relative
|
8
|
-
require
|
6
|
+
require_relative "client"
|
7
|
+
require "io/stream"
|
9
8
|
|
10
9
|
module Async
|
11
10
|
module Redis
|
@@ -107,20 +106,20 @@ module Async
|
|
107
106
|
shards = RangeMap.new
|
108
107
|
endpoints = []
|
109
108
|
|
110
|
-
client.call(
|
109
|
+
client.call("CLUSTER", "SHARDS").each do |shard|
|
111
110
|
shard = shard.each_slice(2).to_h
|
112
111
|
|
113
|
-
slots = shard[
|
112
|
+
slots = shard["slots"]
|
114
113
|
range = Range.new(*slots)
|
115
114
|
|
116
|
-
nodes = shard[
|
115
|
+
nodes = shard["nodes"].map do |node|
|
117
116
|
node = node.each_slice(2).to_h
|
118
|
-
endpoint = Endpoint.remote(node[
|
117
|
+
endpoint = Endpoint.remote(node["ip"], node["port"])
|
119
118
|
|
120
119
|
# Collect all endpoints:
|
121
120
|
endpoints << endpoint
|
122
121
|
|
123
|
-
Node.new(node[
|
122
|
+
Node.new(node["id"], endpoint, node["role"].to_sym, node["health"].to_sym)
|
124
123
|
end
|
125
124
|
|
126
125
|
shards.add(range, nodes)
|
@@ -193,8 +192,8 @@ module Async
|
|
193
192
|
def slot_for(key)
|
194
193
|
key = key.to_s
|
195
194
|
|
196
|
-
if s = key.index(
|
197
|
-
if e = key.index(
|
195
|
+
if s = key.index("{")
|
196
|
+
if e = key.index("}", s + 1) and e != s + 1
|
198
197
|
key = key[s + 1..e - 1]
|
199
198
|
end
|
200
199
|
end
|
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2018, by Huba Nagy.
|
5
|
-
# Copyright, 2018-
|
5
|
+
# Copyright, 2018-2024, by Samuel Williams.
|
6
6
|
|
7
|
-
require_relative
|
7
|
+
require_relative "generic"
|
8
8
|
|
9
9
|
module Async
|
10
10
|
module Redis
|
11
11
|
module Context
|
12
12
|
class Subscribe < Generic
|
13
|
-
MESSAGE =
|
13
|
+
MESSAGE = "message"
|
14
14
|
|
15
15
|
def initialize(pool, channels)
|
16
16
|
super(pool)
|
@@ -31,13 +31,21 @@ module Async
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def each
|
35
|
+
return to_enum unless block_given?
|
36
|
+
|
37
|
+
while response = self.listen
|
38
|
+
yield response
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
34
42
|
def subscribe(channels)
|
35
|
-
@connection.write_request [
|
43
|
+
@connection.write_request ["SUBSCRIBE", *channels]
|
36
44
|
@connection.flush
|
37
45
|
end
|
38
46
|
|
39
47
|
def unsubscribe(channels)
|
40
|
-
@connection.write_request [
|
48
|
+
@connection.write_request ["UNSUBSCRIBE", *channels]
|
41
49
|
@connection.flush
|
42
50
|
end
|
43
51
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# Copyright, 2018, by Huba Nagy.
|
5
5
|
# Copyright, 2018-2023, by Samuel Williams.
|
6
6
|
|
7
|
-
require_relative
|
7
|
+
require_relative "pipeline"
|
8
8
|
|
9
9
|
module Async
|
10
10
|
module Redis
|
@@ -15,20 +15,20 @@ module Async
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def multi
|
18
|
-
call(
|
18
|
+
call("MULTI")
|
19
19
|
end
|
20
20
|
|
21
21
|
def watch(*keys)
|
22
|
-
sync.call(
|
22
|
+
sync.call("WATCH", *keys)
|
23
23
|
end
|
24
24
|
|
25
25
|
# Execute all queued commands, provided that no watched keys have been modified. It's important to note that even when a command fails, all the other commands in the queue are processed – Redis will not stop the processing of commands.
|
26
26
|
def execute
|
27
|
-
sync.call(
|
27
|
+
sync.call("EXEC")
|
28
28
|
end
|
29
29
|
|
30
30
|
def discard
|
31
|
-
sync.call(
|
31
|
+
sync.call("DISCARD")
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/async/redis/endpoint.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2024, by Samuel Williams.
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
6
|
+
require "io/endpoint"
|
7
|
+
require "io/endpoint/host_endpoint"
|
8
|
+
require "io/endpoint/ssl_endpoint"
|
9
9
|
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
10
|
+
require_relative "protocol/resp2"
|
11
|
+
require_relative "protocol/authenticated"
|
12
|
+
require_relative "protocol/selected"
|
13
13
|
|
14
14
|
module Async
|
15
15
|
module Redis
|
@@ -30,8 +30,8 @@ module Async
|
|
30
30
|
end
|
31
31
|
|
32
32
|
SCHEMES = {
|
33
|
-
|
34
|
-
|
33
|
+
"redis" => URI::Generic,
|
34
|
+
"rediss" => URI::Generic,
|
35
35
|
}
|
36
36
|
|
37
37
|
def self.parse(string, endpoint = nil, **options)
|
@@ -117,7 +117,7 @@ module Async
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def secure?
|
120
|
-
[
|
120
|
+
["rediss"].include?(self.scheme)
|
121
121
|
end
|
122
122
|
|
123
123
|
def protocol
|
@@ -3,14 +3,15 @@
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2020, by David Ortiz.
|
5
5
|
# Copyright, 2023-2024, by Samuel Williams.
|
6
|
+
# Copyright, 2024, by Joan Lledó.
|
6
7
|
|
7
|
-
require_relative
|
8
|
-
require
|
8
|
+
require_relative "client"
|
9
|
+
require "io/stream"
|
9
10
|
|
10
11
|
module Async
|
11
12
|
module Redis
|
12
13
|
class SentinelClient
|
13
|
-
DEFAULT_MASTER_NAME =
|
14
|
+
DEFAULT_MASTER_NAME = "mymaster"
|
14
15
|
|
15
16
|
include ::Protocol::Redis::Methods
|
16
17
|
include Client::Methods
|
@@ -30,7 +31,7 @@ module Async
|
|
30
31
|
# A cache of sentinel connections.
|
31
32
|
@sentinels = {}
|
32
33
|
|
33
|
-
@pool =
|
34
|
+
@pool = make_pool(**options)
|
34
35
|
end
|
35
36
|
|
36
37
|
# @attribute [String] The name of the master instance.
|
@@ -64,26 +65,26 @@ module Async
|
|
64
65
|
|
65
66
|
def failover(name = @master_name)
|
66
67
|
sentinels do |client|
|
67
|
-
return client.call(
|
68
|
+
return client.call("SENTINEL", "FAILOVER", name)
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
71
72
|
def masters
|
72
73
|
sentinels do |client|
|
73
|
-
return client.call(
|
74
|
+
return client.call("SENTINEL", "MASTERS").map{|fields| fields.each_slice(2).to_h}
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
77
78
|
def master(name = @master_name)
|
78
79
|
sentinels do |client|
|
79
|
-
return client.call(
|
80
|
+
return client.call("SENTINEL", "MASTER", name).each_slice(2).to_h
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
83
84
|
def resolve_master
|
84
85
|
sentinels do |client|
|
85
86
|
begin
|
86
|
-
address = client.call(
|
87
|
+
address = client.call("SENTINEL", "GET-MASTER-ADDR-BY-NAME", @master_name)
|
87
88
|
rescue Errno::ECONNREFUSED
|
88
89
|
next
|
89
90
|
end
|
@@ -97,7 +98,7 @@ module Async
|
|
97
98
|
def resolve_slave
|
98
99
|
sentinels do |client|
|
99
100
|
begin
|
100
|
-
reply = client.call(
|
101
|
+
reply = client.call("SENTINEL", "SLAVES", @master_name)
|
101
102
|
rescue Errno::ECONNREFUSED
|
102
103
|
next
|
103
104
|
end
|
@@ -106,7 +107,7 @@ module Async
|
|
106
107
|
next if slaves.empty?
|
107
108
|
|
108
109
|
slave = select_slave(slaves)
|
109
|
-
return Endpoint.remote(slave[
|
110
|
+
return Endpoint.remote(slave["ip"], slave["port"])
|
110
111
|
end
|
111
112
|
|
112
113
|
return nil
|
@@ -114,8 +115,14 @@ module Async
|
|
114
115
|
|
115
116
|
protected
|
116
117
|
|
118
|
+
def assign_default_tags(tags)
|
119
|
+
tags[:protocol] = @protocol.to_s
|
120
|
+
end
|
121
|
+
|
117
122
|
# Override the parent method. The only difference is that this one needs to resolve the master/slave address.
|
118
|
-
def
|
123
|
+
def make_pool(**options)
|
124
|
+
self.assign_default_tags(options[:tags] ||= {})
|
125
|
+
|
119
126
|
Async::Pool::Controller.wrap(**options) do
|
120
127
|
endpoint = resolve_address
|
121
128
|
peer = endpoint.connect
|
@@ -141,7 +148,7 @@ module Async
|
|
141
148
|
slaves = reply.map{|fields| fields.each_slice(2).to_h}
|
142
149
|
|
143
150
|
slaves.reject do |slave|
|
144
|
-
slave[
|
151
|
+
slave["flags"].split(",").include?("s_down")
|
145
152
|
end
|
146
153
|
end
|
147
154
|
|
data/lib/async/redis/version.rb
CHANGED
data/lib/async/redis.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2018-
|
4
|
+
# Copyright, 2018-2024, by Samuel Williams.
|
5
5
|
# Copyright, 2020, by David Ortiz.
|
6
6
|
|
7
|
-
require_relative
|
8
|
-
require_relative
|
7
|
+
require_relative "redis/version"
|
8
|
+
require_relative "redis/client"
|
9
9
|
|
10
|
-
require_relative
|
11
|
-
require_relative
|
10
|
+
require_relative "redis/cluster_client"
|
11
|
+
require_relative "redis/sentinel_client"
|
data/license.md
CHANGED
@@ -12,6 +12,7 @@ Copyright, 2021, by Olle Jonsson.
|
|
12
12
|
Copyright, 2021, by Troex Nevelin.
|
13
13
|
Copyright, 2022, by Tim Willard.
|
14
14
|
Copyright, 2022, by Gleb Sinyavskiy.
|
15
|
+
Copyright, 2024, by Joan Lledó.
|
15
16
|
|
16
17
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
17
18
|
of this software and associated documentation files (the "Software"), to deal
|
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.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -12,6 +12,7 @@ authors:
|
|
12
12
|
- Troex Nevelin
|
13
13
|
- Alex Matchneer
|
14
14
|
- Jeremy Jung
|
15
|
+
- Joan Lledó
|
15
16
|
- Olle Jonsson
|
16
17
|
- Pierre Montelle
|
17
18
|
- Salim Semaoune
|
@@ -48,7 +49,7 @@ cert_chain:
|
|
48
49
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
49
50
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
50
51
|
-----END CERTIFICATE-----
|
51
|
-
date: 2024-
|
52
|
+
date: 2024-11-12 00:00:00.000000000 Z
|
52
53
|
dependencies:
|
53
54
|
- !ruby/object:Gem::Dependency
|
54
55
|
name: async
|
@@ -164,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
165
|
- !ruby/object:Gem::Version
|
165
166
|
version: '0'
|
166
167
|
requirements: []
|
167
|
-
rubygems_version: 3.5.
|
168
|
+
rubygems_version: 3.5.22
|
168
169
|
signing_key:
|
169
170
|
specification_version: 4
|
170
171
|
summary: A Redis client library.
|
metadata.gz.sig
CHANGED
Binary file
|