Missing "connection" method
Closed this issue · 3 comments
hlascelles commented
There is a method on the Redis client that allows getting connection
information:
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "redis", "4.2.2"
gem "mock_redis", "0.20.0"
end
puts Redis.new.connection
# => {:host=>"127.0.0.1", :port=>6379, :db=>0, :id=>"redis://127.0.0.1:6379/0", :location=>"127.0.0.1:6379"}
puts MockRedis.new.connection
# => Bang!
# `method_missing': undefined method `connection' for #<MockRedis::Database> (NoMethodError)
I may be doing something non-idiomatic to get that info, but if I am not... should this method exist?
And should it return a "localhost"-ish value like above?
hlascelles commented
For now we are using this wrapper:
# If Redis.current is not a Redis, it is a MockRedis
def connection_details
current = Redis.current
if current.is_a?(Redis)
current.connection
else
current.options.merge(id: "mock_redis")
end
end
sds commented
Would welcome a pull request adding an implementation for this, though it's unclear what the values should be as there isn't an actual TCP port being exposed.
hlascelles commented
Opened! #201
I have just gone with the default port (or, actually, just pulled it from base
).