Skip to content

Handle RedisClient::NoScriptError #1311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/redis/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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)
Expand Down
5 changes: 5 additions & 0 deletions lib/redis/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/redis/scripting_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"), {})
Expand Down
Loading