Skip to content

Commit

Permalink
Preserve passed options hash on Redis.connect.
Browse files Browse the repository at this point in the history
  • Loading branch information
soveran committed Jul 30, 2010
1 parent 9daedf4 commit ec78af5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def self.deprecate(message, trace = caller[0])
attr :client

def self.connect(options = {})
options = options.dup

require "uri"

url = URI(options.delete(:url) || ENV["REDIS_URL"] || "redis://127.0.0.1:6379/0")
Expand Down
8 changes: 8 additions & 0 deletions test/redis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class RedisTest < Test::Unit::TestCase
assert_equal "secr3t", redis.client.password
end

test "doesn not modify the passed options" do
options = { :url => "redis://:secr3t@foo.com:999/2" }

redis = Redis.connect(options)

assert_equal({ :url => "redis://:secr3t@foo.com:999/2" }, options)
end

test "uses REDIS_URL over default if available" do
ENV["REDIS_URL"] = "redis://:secr3t@foo.com:999/2"

Expand Down

0 comments on commit ec78af5

Please sign in to comment.