Skip to content

Commit

Permalink
Bump minimum Ruby version to 2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Aug 12, 2022
1 parent 8fa6593 commit 12497e6
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 158 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.4"
ruby-version: "2.5"
- name: Set up Gems
run: |
gem update --system --no-document
Expand All @@ -33,7 +33,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["3.1", "3.0", "2.7", "2.6", "2.5", "2.4"]
ruby: ["3.1", "3.0", "2.7", "2.6", "2.5"]
runs-on: ubuntu-latest
env:
VERBOSE: "true"
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.4"
ruby-version: "2.5"
bundler-cache: true
- name: Cache local temporary directory
uses: actions/cache@v3
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.4"
ruby-version: "2.5"
bundler-cache: true
- name: Cache local temporary directory
uses: actions/cache@v3
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.4"
ruby-version: "2.5"
bundler-cache: true
- name: Cache local temporary directory
uses: actions/cache@v3
Expand Down Expand Up @@ -209,7 +209,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.4"
ruby-version: "2.5"
bundler-cache: true
- name: Cache local temporary directory
uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.5

Layout/LineLength:
Max: 120
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Unreleased 5.0.0

- Require Ruby 2.5+.
- Removed the deprecated `queue` and `commit` methods. Use `pipelined` instead.
- Removed the deprecated `pipelined` and `multi` signature. Commands now MUST be called on the block argument, not the original redis instance.
- Removed `Redis.current`. You shouldn't assume there is a single global Redis connection, use a connection pool instead,
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gemspec

gem 'minitest'
gem 'rake'
gem 'rubocop', '~> 1.0', '< 1.12'
gem 'rubocop', '~> 1.25.1'

# Using jruby-openssl 0.10.0, we get NPEs in jruby tests: https://github.com/redis/redis-rb/issues/756
platform :jruby do
Expand Down
6 changes: 2 additions & 4 deletions examples/sentinel/start
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ pids = []

at_exit do
pids.each do |pid|
begin
Process.kill(:INT, pid)
rescue Errno::ESRCH
end
Process.kill(:INT, pid)
rescue Errno::ESRCH
end

Process.waitall
Expand Down
20 changes: 9 additions & 11 deletions lib/redis/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,16 @@ def call_pipeline(pipeline)
return [] if pipeline.futures.empty?

with_reconnect pipeline.with_reconnect? do
begin
pipeline.finish(call_pipelined(pipeline)).tap do
self.db = pipeline.db if pipeline.db
end
rescue ConnectionError => e
return nil if pipeline.shutdown?

# Assume the pipeline was sent in one piece, but execution of
# SHUTDOWN caused none of the replies for commands that were executed
# prior to it from coming back around.
raise e
pipeline.finish(call_pipelined(pipeline)).tap do
self.db = pipeline.db if pipeline.db
end
rescue ConnectionError => e
return nil if pipeline.shutdown?

# Assume the pipeline was sent in one piece, but execution of
# SHUTDOWN caused none of the replies for commands that were executed
# prior to it from coming back around.
raise e
end
end

Expand Down
8 changes: 3 additions & 5 deletions lib/redis/cluster/command_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ module CommandLoader

def load(nodes)
errors = nodes.map do |node|
begin
return fetch_command_details(node)
rescue CannotConnectError, ConnectionError, CommandError => error
error
end
return fetch_command_details(node)
rescue CannotConnectError, ConnectionError, CommandError => error
error
end

raise InitialSetupError, errors
Expand Down
12 changes: 5 additions & 7 deletions lib/redis/cluster/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,11 @@ def try_map
results = {}

@clients.each do |node_key, client|
begin
reply = yield(node_key, client)
results[node_key] = reply unless reply.nil?
rescue CommandError => err
errors[node_key] = err
next
end
reply = yield(node_key, client)
results[node_key] = reply unless reply.nil?
rescue CommandError => err
errors[node_key] = err
next
end

return results if errors.empty?
Expand Down
8 changes: 3 additions & 5 deletions lib/redis/cluster/node_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ module NodeLoader

def load_flags(nodes)
errors = nodes.map do |node|
begin
return fetch_node_info(node)
rescue CannotConnectError, ConnectionError, CommandError => error
error
end
return fetch_node_info(node)
rescue CannotConnectError, ConnectionError, CommandError => error
error
end

raise InitialSetupError, errors
Expand Down
2 changes: 1 addition & 1 deletion lib/redis/cluster/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def parse_node_url(addr)
end

def parse_node_option(addr)
addr = addr.map { |k, v| [k.to_sym, v] }.to_h
addr = addr.to_h { |k, v| [k.to_sym, v] }
if addr.values_at(:host, :port).any?(&:nil?)
raise InvalidClientOptionError, 'Redis option of `cluster` must includes `:host` and `:port` keys'
end
Expand Down
8 changes: 3 additions & 5 deletions lib/redis/cluster/slot_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ module SlotLoader

def load(nodes)
errors = nodes.map do |node|
begin
return fetch_slot_info(node)
rescue CannotConnectError, ConnectionError, CommandError => error
error
end
return fetch_slot_info(node)
rescue CannotConnectError, ConnectionError, CommandError => error
error
end

raise InitialSetupError, errors
Expand Down
10 changes: 4 additions & 6 deletions lib/redis/commands/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ def select(db)
# @return [String] `OK`
def quit
synchronize do |client|
begin
client.call([:quit])
rescue ConnectionError
ensure
client.disconnect
end
client.call([:quit])
rescue ConnectionError
ensure
client.disconnect
end
end
end
Expand Down
10 changes: 4 additions & 6 deletions lib/redis/commands/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,10 @@ def save
def shutdown
synchronize do |client|
client.with_reconnect(false) do
begin
client.call([:shutdown])
rescue ConnectionError
# This means Redis has probably exited.
nil
end
client.call([:shutdown])
rescue ConnectionError
# This means Redis has probably exited.
nil
end
end
end
Expand Down
10 changes: 4 additions & 6 deletions lib/redis/connection/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,10 @@ def self.connect(host, port, timeout)
# within getaddrinfo() is defined in RFC 3484 [...].
#
addrinfo.each_with_index do |ai, i|
begin
return connect_addrinfo(ai, port, timeout)
rescue SystemCallError
# Raise if this was our last attempt.
raise if addrinfo.length == i + 1
end
return connect_addrinfo(ai, port, timeout)
rescue SystemCallError
# Raise if this was our last attempt.
raise if addrinfo.length == i + 1
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion redis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Gem::Specification.new do |s|
s.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "lib/**/*"]
s.executables = `git ls-files -- exe/*`.split("\n").map { |f| File.basename(f) }

s.required_ruby_version = '>= 2.4.0'
s.required_ruby_version = '>= 2.5.0'

s.add_development_dependency("hiredis")
s.add_development_dependency("mocha")
Expand Down
3 changes: 1 addition & 2 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ def redis_cluster_mock(commands, options = {})

cluster_subcommands = if commands.key?(:cluster)
commands.delete(:cluster)
.map { |k, v| [k.to_s.downcase, v] }
.to_h
.to_h { |k, v| [k.to_s.downcase, v] }
else
{}
end
Expand Down
38 changes: 16 additions & 22 deletions test/redis/error_replies_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,34 @@ def with_reconnection_check

def test_error_reply_for_single_command
with_reconnection_check do
begin
r.unknown_command
rescue => ex
ensure
assert ex.message =~ /unknown command/i
end
r.unknown_command
rescue => ex
ensure
assert ex.message =~ /unknown command/i
end
end

def test_raise_first_error_reply_in_pipeline
with_reconnection_check do
begin
r.pipelined do
r.set("foo", "s1")
r.incr("foo") # not an integer
r.lpush("foo", "value") # wrong kind of value
end
rescue => ex
ensure
assert ex.message =~ /not an integer/i
r.pipelined do
r.set("foo", "s1")
r.incr("foo") # not an integer
r.lpush("foo", "value") # wrong kind of value
end
rescue => ex
ensure
assert ex.message =~ /not an integer/i
end
end

def test_recover_from_raise_in__call_loop
with_reconnection_check do
begin
r._client.call_loop([:invalid_monitor]) do
assert false # Should never be executed
end
rescue => ex
ensure
assert ex.message =~ /unknown command/i
r._client.call_loop([:invalid_monitor]) do
assert false # Should never be executed
end
rescue => ex
ensure
assert ex.message =~ /unknown command/i
end
end
end
36 changes: 16 additions & 20 deletions test/redis/fork_safety_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ def test_fork_safety
redis.set "foo", 1

child_pid = fork do
begin
# InheritedError triggers a reconnect,
# so we need to disable reconnects to force
# the exception bubble up
redis.without_reconnect do
redis.set "foo", 2
end
exit! 0
rescue Redis::InheritedError
exit! 127
# InheritedError triggers a reconnect,
# so we need to disable reconnects to force
# the exception bubble up
redis.without_reconnect do
redis.set "foo", 2
end
exit! 0
rescue Redis::InheritedError
exit! 127
end

_, status = Process.wait2(child_pid)
Expand All @@ -37,17 +35,15 @@ def test_fork_safety_with_enabled_inherited_socket
redis.set "foo", 1

child_pid = fork do
begin
# InheritedError triggers a reconnect,
# so we need to disable reconnects to force
# the exception bubble up
redis.without_reconnect do
redis.set "foo", 2
end
exit! 0
rescue Redis::InheritedError
exit! 127
# InheritedError triggers a reconnect,
# so we need to disable reconnects to force
# the exception bubble up
redis.without_reconnect do
redis.set "foo", 2
end
exit! 0
rescue Redis::InheritedError
exit! 127
end

_, status = Process.wait2(child_pid)
Expand Down
Loading

0 comments on commit 12497e6

Please sign in to comment.