Skip to content

Commit 7f20192

Browse files
committed
Update cluster tests
1 parent 036c3c1 commit 7f20192

35 files changed

+210
-1521
lines changed

.github/workflows/test.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ jobs:
197197
LOW_TIMEOUT: "0.14"
198198
DRIVER: ruby
199199
REDIS_BRANCH: "7.0"
200+
REDIS_CLUSTER: "true"
200201
steps:
201202
- name: Check out code
202203
uses: actions/checkout@v3
@@ -209,15 +210,15 @@ jobs:
209210
- name: Set up Ruby
210211
uses: ruby/setup-ruby@v1
211212
with:
212-
ruby-version: "2.5"
213+
ruby-version: "2.7"
213214
bundler-cache: true
214215
- name: Cache local temporary directory
215216
uses: actions/cache@v3
216217
with:
217218
path: tmp
218219
key: "local-tmp-redis-7.0-on-ubuntu-latest"
219220
- name: Booting up Redis
220-
run: make start_cluster
221+
run: make start start_cluster create_cluster
221222
- name: Test
222223
run: bundle exec rake test:cluster
223224
- name: Shutting down Redis

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ gem 'rubocop', '~> 1.25.1'
1010
gem 'mocha'
1111

1212
gem 'redis-client'
13-
gem 'hiredis-client', platform: :ruby
13+
gem 'hiredis-client'
14+
gem 'redis-cluster-client', github: 'redis-rb/redis-cluster-client' if ENV['REDIS_CLUSTER']

benchmarking/cluster_slot.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.

bin/cluster_creator

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env ruby
22
# frozen_string_literal: true
33

4+
puts ARGV.join(" ")
45
require 'bundler/setup'
56

67
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
78
require_relative '../test/support/cluster/orchestrator'
89

910
urls = ARGV.map { |host_port| "redis://#{host_port}" }
10-
orchestrator = ClusterOrchestrator.new(urls, timeout: 30.0)
11+
orchestrator = ClusterOrchestrator.new(urls, timeout: 3.0)
1112
orchestrator.rebuild
1213
orchestrator.close

lib/redis.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class Redis
88
BASE_PATH = __dir__
99
Deprecated = Class.new(StandardError)
1010

11+
autoload :ClusterClient, "redis/cluster_client"
12+
1113
class << self
1214
attr_accessor :silence_deprecations, :raise_deprecations
1315

@@ -67,7 +69,13 @@ def initialize(options = {})
6769
@subscription_client = nil
6870

6971
@client = if @cluster_mode = options.key?(:cluster)
70-
Cluster.new(@options)
72+
@options[:nodes] ||= @options.delete(:cluster)
73+
cluster_config = RedisClient.cluster(**@options, protocol: 2, client_implementation: ClusterClient)
74+
begin
75+
cluster_config.new_client
76+
rescue ::RedisClient::Error => error
77+
raise ClusterClient::ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
78+
end
7179
elsif @options.key?(:sentinels)
7280
if url = @options.delete(:url)
7381
uri = URI.parse(url)
@@ -86,7 +94,7 @@ def initialize(options = {})
8694

8795
Client.sentinel(**@options).new_client
8896
else
89-
Client.new(@options)
97+
Client.config(**@options).new_client
9098
end
9199
@client.inherit_socket! if inherit_socket
92100
end
@@ -125,7 +133,7 @@ def pipelined
125133
end
126134

127135
def id
128-
@client.config.id || @client.config.server_url
136+
@client.id || @client.server_url
129137
end
130138

131139
def inspect
@@ -137,7 +145,9 @@ def dup
137145
end
138146

139147
def connection
140-
return @client.connection_info if @cluster_mode
148+
if @cluster_mode
149+
raise NotImplementedError, "Redis::Cluster doesn't implement #connection"
150+
end
141151

142152
{
143153
host: @client.host,
@@ -186,6 +196,5 @@ def _subscription(method, timeout, channels, block)
186196

187197
require "redis/version"
188198
require "redis/client"
189-
require "redis/cluster"
190199
require "redis/pipeline"
191200
require "redis/subscribe"

lib/redis/client.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def initialize(*)
3434
end
3535
ruby2_keywords :initialize if respond_to?(:ruby2_keywords, true)
3636

37+
def id
38+
config.id
39+
end
40+
3741
def server_url
3842
config.server_url
3943
end
@@ -68,6 +72,7 @@ def password
6872

6973
undef_method :call
7074
undef_method :call_once
75+
undef_method :call_once_v
7176
undef_method :blocking_call
7277

7378
def call_v(command, &block)
@@ -76,8 +81,9 @@ def call_v(command, &block)
7681
raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
7782
end
7883

79-
def multi
80-
super
84+
def blocking_call_v(timeout, command, &block)
85+
timeout += self.timeout if timeout && timeout > 0
86+
super(timeout, command, &block)
8187
rescue ::RedisClient::Error => error
8288
raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
8389
end
@@ -88,9 +94,8 @@ def pipelined
8894
raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
8995
end
9096

91-
def blocking_call_v(timeout, command, &block)
92-
timeout += self.timeout if timeout && timeout > 0
93-
super(timeout, command, &block)
97+
def multi
98+
super
9499
rescue ::RedisClient::Error => error
95100
raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
96101
end

0 commit comments

Comments
 (0)