redmon
redmon copied to clipboard
connect to Redis using Unix Socket
How do I connect to a Redis instance using a Unix Socket?
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?
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
The if statement will raise Errno::ENOENT exception when value from Redmon.config.redis_url is not a file or does not exist.