redis-cluster-client 0.6.1 → 0.7.0
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/concurrent_worker/none.rb +4 -0
- data/lib/redis_client/cluster/concurrent_worker/on_demand.rb +4 -0
- data/lib/redis_client/cluster/concurrent_worker/pooled.rb +8 -2
- data/lib/redis_client/cluster/concurrent_worker.rb +5 -1
- data/lib/redis_client/cluster/router.rb +6 -0
- data/lib/redis_client/cluster/transaction.rb +56 -0
- data/lib/redis_client/cluster.rb +8 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a24c43fc85a464dd886dfd38358b05fbd281247e8ab2b5420aa262003419c4d3
|
4
|
+
data.tar.gz: d0080c21c84bf7827bd352aac12a31fb84ba14b57e293f8275ccbb6efa96b326
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b23b9967900f0ea14db0c4c2049389db73ed083304ad13641e55268a0278028fc4e231d495d65d0658125116bfd31dd47cd07394d487d7a83b0a97262d30c30
|
7
|
+
data.tar.gz: 55df5f327713a8d8597dcdd63e7803b40e99610e51792f1628aa4bc2ccc6f1e0da95579a246232b328c09061d51cd448dc4a7e9f8abf97d2f06b85e7a659fe88
|
@@ -38,6 +38,10 @@ class RedisClient
|
|
38
38
|
nil
|
39
39
|
end
|
40
40
|
|
41
|
+
def inspect
|
42
|
+
"#<#{self.class.name} tasks: #{@q.size}, workers: #{@size}>"
|
43
|
+
end
|
44
|
+
|
41
45
|
private
|
42
46
|
|
43
47
|
def setup
|
@@ -52,13 +56,15 @@ class RedisClient
|
|
52
56
|
end
|
53
57
|
|
54
58
|
def ensure_workers
|
55
|
-
@
|
59
|
+
@size.times do |i|
|
56
60
|
@workers[i] = spawn_worker unless @workers[i]&.alive?
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
60
64
|
def spawn_worker
|
61
|
-
Thread.new(@q)
|
65
|
+
Thread.new(@q) do |q|
|
66
|
+
loop { q.pop.exec }
|
67
|
+
end
|
62
68
|
end
|
63
69
|
end
|
64
70
|
end
|
@@ -7,7 +7,7 @@ require 'redis_client/cluster/concurrent_worker/none'
|
|
7
7
|
class RedisClient
|
8
8
|
class Cluster
|
9
9
|
module ConcurrentWorker
|
10
|
-
InvalidNumberOfTasks = Class.new(
|
10
|
+
InvalidNumberOfTasks = Class.new(StandardError)
|
11
11
|
|
12
12
|
class Group
|
13
13
|
Task = Struct.new(
|
@@ -63,6 +63,10 @@ class RedisClient
|
|
63
63
|
@count = 0
|
64
64
|
nil
|
65
65
|
end
|
66
|
+
|
67
|
+
def inspect
|
68
|
+
"#<#{self.class.name} size: #{@count}, max: #{@size}, worker: #{@worker.class.name}>"
|
69
|
+
end
|
66
70
|
end
|
67
71
|
|
68
72
|
module_function
|
@@ -179,6 +179,12 @@ class RedisClient
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
+
def find_primary_node_key(command)
|
183
|
+
key = @command.extract_first_key(command)
|
184
|
+
slot = key.empty? ? nil : ::RedisClient::Cluster::KeySlotConverter.convert(key)
|
185
|
+
@node.find_node_key_of_primary(slot)
|
186
|
+
end
|
187
|
+
|
182
188
|
def find_node(node_key, retry_count: 3)
|
183
189
|
@node.find_by(node_key)
|
184
190
|
rescue ::RedisClient::Cluster::Node::ReloadNeeded
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'redis_client'
|
4
|
+
|
5
|
+
class RedisClient
|
6
|
+
class Cluster
|
7
|
+
class Transaction
|
8
|
+
ConsistencyError = Class.new(::RedisClient::Error)
|
9
|
+
|
10
|
+
def initialize(router, command_builder)
|
11
|
+
@router = router
|
12
|
+
@command_builder = command_builder
|
13
|
+
@node_key = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(*command, **kwargs, &_)
|
17
|
+
command = @command_builder.generate(command, kwargs)
|
18
|
+
ensure_node_key(command)
|
19
|
+
end
|
20
|
+
|
21
|
+
def call_v(command, &_)
|
22
|
+
command = @command_builder.generate(command)
|
23
|
+
ensure_node_key(command)
|
24
|
+
end
|
25
|
+
|
26
|
+
def call_once(*command, **kwargs, &_)
|
27
|
+
command = @command_builder.generate(command, kwargs)
|
28
|
+
ensure_node_key(command)
|
29
|
+
end
|
30
|
+
|
31
|
+
def call_once_v(command, &_)
|
32
|
+
command = @command_builder.generate(command)
|
33
|
+
ensure_node_key(command)
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_node
|
37
|
+
yield self
|
38
|
+
raise ArgumentError, 'empty transaction' if @node_key.nil?
|
39
|
+
|
40
|
+
@router.find_node(@node_key)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def ensure_node_key(command)
|
46
|
+
node_key = @router.find_primary_node_key(command)
|
47
|
+
raise ConsistencyError, "Client couldn't determine the node to be executed the transaction by: #{command}" if node_key.nil?
|
48
|
+
|
49
|
+
@node_key ||= node_key
|
50
|
+
raise ConsistencyError, "The transaction should be done for single node: #{@node_key}, #{node_key}" if node_key != @node_key
|
51
|
+
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/redis_client/cluster.rb
CHANGED
@@ -4,6 +4,7 @@ require 'redis_client/cluster/concurrent_worker'
|
|
4
4
|
require 'redis_client/cluster/pipeline'
|
5
5
|
require 'redis_client/cluster/pub_sub'
|
6
6
|
require 'redis_client/cluster/router'
|
7
|
+
require 'redis_client/cluster/transaction'
|
7
8
|
|
8
9
|
class RedisClient
|
9
10
|
class Cluster
|
@@ -88,6 +89,13 @@ class RedisClient
|
|
88
89
|
pipeline.execute
|
89
90
|
end
|
90
91
|
|
92
|
+
def multi(watch: nil, &block)
|
93
|
+
::RedisClient::Cluster::Transaction
|
94
|
+
.new(@router, @command_builder)
|
95
|
+
.find_node(&block)
|
96
|
+
.multi(watch: watch, &block)
|
97
|
+
end
|
98
|
+
|
91
99
|
def pubsub
|
92
100
|
::RedisClient::Cluster::PubSub.new(@router, @command_builder)
|
93
101
|
end
|
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.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taishi Kasuga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-client
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/redis_client/cluster/pipeline.rb
|
52
52
|
- lib/redis_client/cluster/pub_sub.rb
|
53
53
|
- lib/redis_client/cluster/router.rb
|
54
|
+
- lib/redis_client/cluster/transaction.rb
|
54
55
|
- lib/redis_client/cluster_config.rb
|
55
56
|
- lib/redis_cluster_client.rb
|
56
57
|
homepage: https://github.com/redis-rb/redis-cluster-client
|