Skip to content

Commit

Permalink
Update cluster tests
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Aug 17, 2022
1 parent 036c3c1 commit 54d8209
Show file tree
Hide file tree
Showing 35 changed files with 188 additions and 1,508 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ jobs:
LOW_TIMEOUT: "0.14"
DRIVER: ruby
REDIS_BRANCH: "7.0"
REDIS_CLUSTER: "true"
steps:
- name: Check out code
uses: actions/checkout@v3
Expand All @@ -209,15 +210,15 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.5"
ruby-version: "2.7"
bundler-cache: true
- name: Cache local temporary directory
uses: actions/cache@v3
with:
path: tmp
key: "local-tmp-redis-7.0-on-ubuntu-latest"
- name: Booting up Redis
run: make start_cluster
run: make start start_cluster create_cluster
- name: Test
run: bundle exec rake test:cluster
- name: Shutting down Redis
Expand Down
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ gem 'rake'
gem 'rubocop', '~> 1.25.1'
gem 'mocha'

gem 'redis-client'
gem 'hiredis-client', platform: :ruby
gem 'redis-client', github: "redis-rb/redis-client"
gem 'hiredis-client', platform: :ruby, github: "redis-rb/redis-client"
gem 'redis-cluster-client', github: 'redis-rb/redis-cluster-client', branch: 'redis-rb-5.0' if ENV['REDIS_CLUSTER']
36 changes: 0 additions & 36 deletions benchmarking/cluster_slot.rb

This file was deleted.

3 changes: 2 additions & 1 deletion bin/cluster_creator
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

puts ARGV.join(" ")
require 'bundler/setup'

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

urls = ARGV.map { |host_port| "redis://#{host_port}" }
orchestrator = ClusterOrchestrator.new(urls, timeout: 30.0)
orchestrator = ClusterOrchestrator.new(urls, timeout: 3.0)
orchestrator.rebuild
orchestrator.close
19 changes: 14 additions & 5 deletions lib/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Redis
BASE_PATH = __dir__
Deprecated = Class.new(StandardError)

autoload :ClusterClient, "redis/cluster_client"

class << self
attr_accessor :silence_deprecations, :raise_deprecations

Expand Down Expand Up @@ -67,7 +69,13 @@ def initialize(options = {})
@subscription_client = nil

@client = if @cluster_mode = options.key?(:cluster)
Cluster.new(@options)
@options[:nodes] ||= @options.delete(:cluster)
cluster_config = RedisClient.cluster(**@options, protocol: 2, client_implementation: ClusterClient)
begin
cluster_config.new_client
rescue ::RedisClient::Error => error
raise ClusterClient::ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
end
elsif @options.key?(:sentinels)
if url = @options.delete(:url)
uri = URI.parse(url)
Expand All @@ -86,7 +94,7 @@ def initialize(options = {})

Client.sentinel(**@options).new_client
else
Client.new(@options)
Client.config(**@options).new_client
end
@client.inherit_socket! if inherit_socket
end
Expand Down Expand Up @@ -125,7 +133,7 @@ def pipelined
end

def id
@client.config.id || @client.config.server_url
@client.id || @client.server_url
end

def inspect
Expand All @@ -137,7 +145,9 @@ def dup
end

def connection
return @client.connection_info if @cluster_mode
if @cluster_mode
raise NotImplementedError, "Redis::Cluster doesn't implement #connection"
end

{
host: @client.host,
Expand Down Expand Up @@ -186,6 +196,5 @@ def _subscription(method, timeout, channels, block)

require "redis/version"
require "redis/client"
require "redis/cluster"
require "redis/pipeline"
require "redis/subscribe"
15 changes: 10 additions & 5 deletions lib/redis/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def initialize(*)
end
ruby2_keywords :initialize if respond_to?(:ruby2_keywords, true)

def id
config.id
end

def server_url
config.server_url
end
Expand Down Expand Up @@ -68,6 +72,7 @@ def password

undef_method :call
undef_method :call_once
undef_method :call_once_v
undef_method :blocking_call

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

def multi
super
def blocking_call_v(timeout, command, &block)
timeout += self.timeout if timeout && timeout > 0
super(timeout, command, &block)
rescue ::RedisClient::Error => error
raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
end
Expand All @@ -88,9 +94,8 @@ def pipelined
raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
end

def blocking_call_v(timeout, command, &block)
timeout += self.timeout if timeout && timeout > 0
super(timeout, command, &block)
def multi
super
rescue ::RedisClient::Error => error
raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
end
Expand Down
Loading

0 comments on commit 54d8209

Please sign in to comment.