-
Notifications
You must be signed in to change notification settings - Fork 69
Closed
Description
Hi there,
We found an issue with redis-client to a setup like this:
RedisClient.config(url: "redis://localhost:6379/3").db
#=> 3
RedisClient.config(url: "redis://localhost:6379/3", db: 2).db
#=> 2
RedisClient.config(url: "redis://localhost:6379/3", db: nil).db
#=> 0The problem here is that we use an environment variable that can be set or not and this lead to the wrong db.
The actual code is more like this:
RedisClient.config(url: ENV["REDIS_URL"], db: ENV["REDIS_DB"]&.to_i).dbThe Redis gem on the other hand, works as expected:
Redis.new(url: "redis://localhost:6379/3", db: nil)
#=> keeps the 3 db
Redis.new(url: "redis://localhost:6379/3", db: 2)
#=> override to the 2 dbThe fix is to not set the db to nil but this was unexpected:
config = { url: ENV["REDIS_URL"] }
config[:db] = ENV["REDIS_DB"].to_i if ENV["REDIS_DB"]
RedisClient.config(config).db
#=> now works as expected if set or unsetWe have a few options here:
- Raise an error if nil
- Raise an error if db is set to something different than the url db
- Respect the original dbnumber if set to nil (my choice)
WDYT?
Metadata
Metadata
Assignees
Labels
No labels