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

connect to Redis using Unix Socket #76

Open
fnkr opened this issue Feb 17, 2015 · 3 comments
Open

connect to Redis using Unix Socket #76

fnkr opened this issue Feb 17, 2015 · 3 comments

Comments

@fnkr
Copy link

fnkr commented Feb 17, 2015

How do I connect to a Redis instance using a Unix Socket?

@steelThread
Copy link
Owner

We use the redis gem which supports a unix socket connection. Don't think we support that as an connection option but I think it would be pretty easy to do. Is this something you want to try and implement in a fork @fnkr?

@fnkr
Copy link
Author

fnkr commented Feb 18, 2015

I'm not a Ruby programmer but as far as I see you just need to create the Ruby object with the path instead of the url parameter.

redis = Redis.new(:url => "redis://:p4ssw0rd@10.0.1.1:6380/15")
redis = Redis.new(:path => "/tmp/redis.sock")

Source: https://github.com/redis/redis-rb/tree/v3.2.1#getting-started

Maybe we check if Redmon.config.redis_url is a unix socket. Something like this:

# http://ruby-doc.org/core-1.9.3/File.html#ftype-method
if File.ftype(Redmon.config.redis_url) == 'socket'
  @redis ||= ::Redis.connect(:path => Redmon.config.redis_url)
else
  @redis ||= ::Redis.connect(:url => Redmon.config.redis_url)
end

https://github.com/steelThread/redmon/blob/v0.0.10/lib/redmon/redis.rb#L18

@kiela
Copy link
Contributor

kiela commented Feb 19, 2015

The if statement will raise Errno::ENOENT exception when value from Redmon.config.redis_url is not a file or does not exist.

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

No branches or pull requests

3 participants