redmon icon indicating copy to clipboard operation
redmon copied to clipboard

connect to Redis using Unix Socket

Open fnkr opened this issue 10 years ago • 3 comments

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

fnkr avatar Feb 17 '15 15:02 fnkr

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?

steelThread avatar Feb 18 '15 02:02 steelThread

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://:[email protected]: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

fnkr avatar Feb 18 '15 07:02 fnkr

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

kiela avatar Feb 19 '15 17:02 kiela