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 16, 2022
1 parent 036c3c1 commit 99784af
Show file tree
Hide file tree
Showing 30 changed files with 128 additions and 1,452 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' 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
13 changes: 10 additions & 3 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 Down Expand Up @@ -137,7 +145,7 @@ def dup
end

def connection
return @client.connection_info if @cluster_mode
raise NotImplementedError if @cluster_mode

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

require "redis/version"
require "redis/client"
require "redis/cluster"
require "redis/pipeline"
require "redis/subscribe"
11 changes: 6 additions & 5 deletions lib/redis/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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 +77,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 +90,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 99784af

Please sign in to comment.