Skip to content
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Unreleased

- Fix precedence of `db: nil` initialization parameter.

```ruby
Redis.new(url: "redis://localhost:6379/3", db: nil).db
```

Before: `0`
After: `3`

# 0.25.3

- Fix `hiredis-client` compilation with `clang 21`.
Expand Down
5 changes: 3 additions & 2 deletions lib/redis_client/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,23 @@ def initialize(
path: nil,
username: nil,
password: nil,
db: nil,
**kwargs
)
if url
url_config = URLConfig.new(url)
kwargs = {
ssl: url_config.ssl?,
db: url_config.db,
}.compact.merge(kwargs)
db ||= url_config.db
host ||= url_config.host
port ||= url_config.port
path ||= url_config.path
username ||= url_config.username
password ||= url_config.password
end

super(username: username, password: password, **kwargs)
super(username: username, password: password, db: db, **kwargs)

if @path = path
@host = nil
Expand Down
17 changes: 17 additions & 0 deletions test/redis_client/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,23 @@ def test_overriding
assert_equal [%w[HELLO 3 AUTH george hunter2], %w[SELECT 5]], config.connection_prelude
end

def test_overriding_nil
config = Config.new(
url: "redis://p%[email protected]:16379/12",
username: nil,
password: nil,
host: nil,
port: nil,
db: nil,
)

assert_equal "redis-16379.hosted.com", config.host
assert_equal 16379, config.port
assert_equal "default", config.username
assert_equal "p@ssw0rd", config.password
assert_equal 12, config.db
end

def test_server_url
assert_equal "redis://localhost:6379", Config.new.server_url
assert_equal "redis://localhost:6379", Config.new(username: "george", password: "hunter2").server_url
Expand Down