diff --git a/CHANGELOG.md b/CHANGELOG.md index a5f4c2ef4..5646f8061 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +# 5.4.1 + +- Properly handle NOSCRIPT errors. + # 5.4.0 - Fix `blmpop` method to actually use `BLMPOP`, it was mistakenly issuing `LMPOP` commands. diff --git a/bin/build b/bin/build index 925a91059..6cbc3c85f 100755 --- a/bin/build +++ b/bin/build @@ -38,7 +38,7 @@ class Builder end def tarball_url - "https://github.com/antirez/redis/archive/#{@redis_branch}.tar.gz" + "https://github.com/redis/redis/archive/#{@redis_branch}.tar.gz" end def build diff --git a/lib/redis.rb b/lib/redis.rb index 09d8fd95c..836beb2f2 100644 --- a/lib/redis.rb +++ b/lib/redis.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "redis-client" + require "monitor" require "redis/errors" require "redis/commands" diff --git a/lib/redis/client.rb b/lib/redis/client.rb index d23ed9122..1acfb3c52 100644 --- a/lib/redis/client.rb +++ b/lib/redis/client.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'redis-client' - class Redis class Client < ::RedisClient ERROR_MAPPING = { @@ -17,6 +15,9 @@ class Client < ::RedisClient RedisClient::ProtocolError => Redis::ProtocolError, RedisClient::OutOfMemoryError => Redis::OutOfMemoryError, } + if defined?(RedisClient::NoScriptError) + ERROR_MAPPING[RedisClient::NoScriptError] = Redis::NoScriptError + end class << self def config(**kwargs) @@ -86,6 +87,12 @@ def password undef_method :call_once_v undef_method :blocking_call + def ensure_connected(retryable: true, &block) + super(retryable: retryable, &block) + rescue ::RedisClient::Error => error + Client.translate_error!(error) + end + def call_v(command, &block) super(command, &block) rescue ::RedisClient::Error => error diff --git a/lib/redis/errors.rb b/lib/redis/errors.rb index bef5a8d45..549067274 100644 --- a/lib/redis/errors.rb +++ b/lib/redis/errors.rb @@ -29,6 +29,11 @@ class WrongTypeError < CommandError class OutOfMemoryError < CommandError end + if defined?(RedisClient::NoScriptError) + class NoScriptError < CommandError + end + end + # Base error for connection related errors. class BaseConnectionError < BaseError end diff --git a/lib/redis/version.rb b/lib/redis/version.rb index ae150cb1b..73ce2adbe 100644 --- a/lib/redis/version.rb +++ b/lib/redis/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class Redis - VERSION = '5.4.0' + VERSION = '5.4.1' end diff --git a/test/lint/hashes.rb b/test/lint/hashes.rb index a6d470220..698c3be22 100644 --- a/test/lint/hashes.rb +++ b/test/lint/hashes.rb @@ -114,7 +114,7 @@ def test_hrandfield assert_equal ["f1", "f2"], r.hrandfield("foo", 2).sort assert_equal 4, r.hrandfield("foo", -4).size - r.hrandfield("foo", 2, with_values: true) do |(field, value)| + r.hrandfield("foo", 2, with_values: true).each do |(field, value)| assert ["f1", "f2"].include?(field) assert ["s1", "s2"].include?(value) end diff --git a/test/redis/scripting_test.rb b/test/redis/scripting_test.rb index f01650122..e3968b4c6 100644 --- a/test/redis/scripting_test.rb +++ b/test/redis/scripting_test.rb @@ -54,6 +54,13 @@ def test_evalsha assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), [], ["a1", "a2"]) end + def test_evalsha_no_script + error = defined?(RedisClient::NoScriptError) ? Redis::NoScriptError : Redis::CommandError + assert_raises error do + redis.evalsha("invalid") + end + end + def test_evalsha_with_options_hash assert_equal 0, r.evalsha(to_sha("return #KEYS"), {}) assert_equal 0, r.evalsha(to_sha("return #ARGV"), {})