redis-cluster-client 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redis_client/cluster/command.rb +2 -2
- data/lib/redis_client/cluster/node/latency_replica.rb +2 -1
- data/lib/redis_client/cluster/node.rb +2 -0
- data/lib/redis_client/cluster/pipeline.rb +17 -15
- data/lib/redis_client/cluster/router.rb +2 -0
- data/lib/redis_client/cluster.rb +2 -1
- data/lib/redis_client/cluster_config.rb +15 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1eaec04db89e1afa8a1d0a27688194d5941a94edb00aef979b1f368d01b4dd41
|
4
|
+
data.tar.gz: 36571e86def197fc3633d4c026958fbe635576d5f9aec3ab19b32759957a8f14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2da9f21f30cc49f9df64cf11ed5ee3c0385bc6310bbb7e8cf3478552272f716ab68928aee05bb90b24d39253040f170fd38df78687afb78ea612f310f6a96b2e
|
7
|
+
data.tar.gz: 4f7828b8072f01aaa5aa56264d7fda6f8d4ff17bce7a88a5adb2c05bd5eab8a74fe137b3c59ce1bba086a9793a05d490252d0df94228e35c6c10a2b0d869d797
|
@@ -72,14 +72,14 @@ class RedisClient
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def dig_details(command, key)
|
75
|
-
name = command&.flatten&.first.to_s.downcase
|
75
|
+
name = command&.flatten&.first.to_s.downcase # OPTIMIZE: prevent allocation for string
|
76
76
|
return if name.empty? || !@details.key?(name)
|
77
77
|
|
78
78
|
@details.fetch(name).fetch(key)
|
79
79
|
end
|
80
80
|
|
81
81
|
def determine_first_key_position(command) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
82
|
-
case command&.flatten&.first.to_s.downcase
|
82
|
+
case command&.flatten&.first.to_s.downcase # OPTIMIZE: prevent allocation for string
|
83
83
|
when 'eval', 'evalsha', 'zinterstore', 'zunionstore' then 3
|
84
84
|
when 'object' then 2
|
85
85
|
when 'memory'
|
@@ -21,6 +21,7 @@ class RedisClient
|
|
21
21
|
@replications.each_value { |keys| keys.sort_by! { |k| latencies.fetch(k) } }
|
22
22
|
@replica_clients = select_replica_clients(@replications, @clients)
|
23
23
|
@clients_for_scanning = select_clients_for_scanning(@replications, @clients)
|
24
|
+
@existed_replicas = @replications.reject { |_, v| v.empty? }.values
|
24
25
|
end
|
25
26
|
|
26
27
|
def clients_for_scanning(seed: nil) # rubocop:disable Lint/UnusedMethodArgument
|
@@ -33,7 +34,7 @@ class RedisClient
|
|
33
34
|
|
34
35
|
def any_replica_node_key(seed: nil)
|
35
36
|
random = seed.nil? ? Random : Random.new(seed)
|
36
|
-
@
|
37
|
+
@existed_replicas.sample(random: random).first
|
37
38
|
end
|
38
39
|
|
39
40
|
private
|
@@ -9,54 +9,48 @@ class RedisClient
|
|
9
9
|
ReplySizeError = Class.new(::RedisClient::Error)
|
10
10
|
MAX_THREADS = Integer(ENV.fetch('REDIS_CLIENT_MAX_THREADS', 5))
|
11
11
|
|
12
|
-
def initialize(router, command_builder)
|
12
|
+
def initialize(router, command_builder, seed: Random.new_seed)
|
13
13
|
@router = router
|
14
14
|
@command_builder = command_builder
|
15
|
-
@grouped =
|
15
|
+
@grouped = {}
|
16
16
|
@size = 0
|
17
|
-
@seed =
|
17
|
+
@seed = seed
|
18
18
|
end
|
19
19
|
|
20
20
|
def call(*args, **kwargs, &block)
|
21
21
|
command = @command_builder.generate(args, kwargs)
|
22
22
|
node_key = @router.find_node_key(command, seed: @seed)
|
23
|
-
|
24
|
-
@size += 1
|
23
|
+
add_line(node_key, [@size, :call_v, command, block])
|
25
24
|
end
|
26
25
|
|
27
26
|
def call_v(args, &block)
|
28
27
|
command = @command_builder.generate(args)
|
29
28
|
node_key = @router.find_node_key(command, seed: @seed)
|
30
|
-
|
31
|
-
@size += 1
|
29
|
+
add_line(node_key, [@size, :call_v, command, block])
|
32
30
|
end
|
33
31
|
|
34
32
|
def call_once(*args, **kwargs, &block)
|
35
33
|
command = @command_builder.generate(args, kwargs)
|
36
34
|
node_key = @router.find_node_key(command, seed: @seed)
|
37
|
-
|
38
|
-
@size += 1
|
35
|
+
add_line(node_key, [@size, :call_once_v, command, block])
|
39
36
|
end
|
40
37
|
|
41
38
|
def call_once_v(args, &block)
|
42
39
|
command = @command_builder.generate(args)
|
43
40
|
node_key = @router.find_node_key(command, seed: @seed)
|
44
|
-
|
45
|
-
@size += 1
|
41
|
+
add_line(node_key, [@size, :call_once_v, command, block])
|
46
42
|
end
|
47
43
|
|
48
44
|
def blocking_call(timeout, *args, **kwargs, &block)
|
49
45
|
command = @command_builder.generate(args, kwargs)
|
50
46
|
node_key = @router.find_node_key(command, seed: @seed)
|
51
|
-
|
52
|
-
@size += 1
|
47
|
+
add_line(node_key, [@size, :blocking_call_v, timeout, command, block])
|
53
48
|
end
|
54
49
|
|
55
50
|
def blocking_call_v(timeout, args, &block)
|
56
51
|
command = @command_builder.generate(args)
|
57
52
|
node_key = @router.find_node_key(command, seed: @seed)
|
58
|
-
|
59
|
-
@size += 1
|
53
|
+
add_line(node_key, [@size, :blocking_call_v, timeout, command, block])
|
60
54
|
end
|
61
55
|
|
62
56
|
def empty?
|
@@ -92,6 +86,14 @@ class RedisClient
|
|
92
86
|
|
93
87
|
raise ::RedisClient::Cluster::ErrorCollection, errors
|
94
88
|
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def add_line(node_key, line)
|
93
|
+
@grouped[node_key] = [] unless @grouped.key?(node_key)
|
94
|
+
@grouped[node_key] << line
|
95
|
+
@size += 1
|
96
|
+
end
|
95
97
|
end
|
96
98
|
end
|
97
99
|
end
|
data/lib/redis_client/cluster.rb
CHANGED
@@ -78,7 +78,8 @@ class RedisClient
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def pipelined
|
81
|
-
|
81
|
+
seed = @config.use_replica? && @config.replica_affinity == :random ? nil : Random.new_seed
|
82
|
+
pipeline = ::RedisClient::Cluster::Pipeline.new(@router, @command_builder, seed: seed)
|
82
83
|
yield pipeline
|
83
84
|
return [] if pipeline.empty? == 0
|
84
85
|
|
@@ -42,6 +42,17 @@ class RedisClient
|
|
42
42
|
@mutex = Mutex.new
|
43
43
|
end
|
44
44
|
|
45
|
+
def dup
|
46
|
+
self.class.new(
|
47
|
+
nodes: @node_configs,
|
48
|
+
replica: @replica,
|
49
|
+
replica_affinity: @replica_affinity,
|
50
|
+
fixed_hostname: @fixed_hostname,
|
51
|
+
client_implementation: @client_implementation,
|
52
|
+
**@client_config
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
45
56
|
def inspect
|
46
57
|
"#<#{self.class.name} #{per_node_key.values}>"
|
47
58
|
end
|
@@ -72,15 +83,15 @@ class RedisClient
|
|
72
83
|
end
|
73
84
|
|
74
85
|
def update_node(addrs)
|
86
|
+
return if @mutex.locked?
|
87
|
+
|
75
88
|
@mutex.synchronize { @node_configs = build_node_configs(addrs) }
|
76
89
|
end
|
77
90
|
|
78
91
|
def add_node(host, port)
|
79
|
-
@mutex.
|
80
|
-
end
|
92
|
+
return if @mutex.locked?
|
81
93
|
|
82
|
-
|
83
|
-
self.class.new(nodes: @node_configs, replica: @replica, fixed_hostname: @fixed_hostname, **@client_config)
|
94
|
+
@mutex.synchronize { @node_configs << { host: host, port: port } }
|
84
95
|
end
|
85
96
|
|
86
97
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-cluster-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taishi Kasuga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-client
|