Skip to content

Commit

Permalink
Only use a default for the shared config
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Dec 27, 2023
1 parent 38e4a34 commit 7453f9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/kredis/connections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ def configured_for(name)
connections[name] ||= Kredis.instrument :meta, message: "Connected to #{name}" do
if configurator.root.join("config/redis/#{name}.yml").exist?
connector.call configurator.config_for("redis/#{name}")
else
elsif name == :shared
Redis.new url: ENV.fetch("REDIS_URL", DEFAULT_REDIS_URL), timeout: DEFAULT_REDIS_TIMEOUT
else
raise "No configuration found for #{name}"
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/connections_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ class ConnectionsTest < ActiveSupport::TestCase
test "default config without env" do
assert_match %r|redis://127.0.0.1:6379/0|, Kredis.redis.inspect
end

test "custom config is missing" do
assert_raises do
Kredis.configured_for(:missing).set "mykey", "won't get set"
end
end
end

0 comments on commit 7453f9a

Please sign in to comment.