Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing "connection" method #197

Closed
hlascelles opened this issue Oct 23, 2020 · 3 comments
Closed

Missing "connection" method #197

hlascelles opened this issue Oct 23, 2020 · 3 comments

Comments

@hlascelles
Copy link
Contributor

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
Copy link
Contributor Author

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 sds added the enhancement label Nov 3, 2020
@sds
Copy link
Owner

sds commented Nov 3, 2020

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
Copy link
Contributor Author

hlascelles commented Dec 27, 2020

Opened! #201

I have just gone with the default port (or, actually, just pulled it from base).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants