Em-hiredis doesn't appear to support unix domain sockets #21

Closed
mcorner opened this Issue Nov 1, 2012 · 2 comments

2 participants

@mcorner

From the redis docs: "The typical latency of a 1 GBits/s network is about 200 us, while the latency with a Unix domain socket can be as low as 30 us. "

It doesn't appear that URI can handle such a thing as: redis:///tmp/redis.sock

Here is a super ugly, quick and dirty, monkey patch to support it in em-hiredis. I humbly apologize for all of its overwhelming ugliness.

require 'em-hiredis'

module EventMachine
module Hiredis
def self.setup(uri = nil)
if uri =~ /^redis:\/\/\//
Client.new(uri.split(/^redis:\/\//)[1],nil,nil,nil)
else
url = URI(uri || ENV["REDIS_URL"] || "redis://127.0.0.1:6379/0")
Client.new(url.host, url.port, url.password, url.path[1..-1])
end
end
end
end

EventMachine.run {
redis = EM::Hiredis.connect("redis:///tmp/redis.sock")
}

You have to add this to your redis server's conf:

create a unix domain socket to listen on

unixsocket /tmp/redis.sock

set permissions for the socket

unixsocketperm 755

@mloughran
Owner

If you clean this up I'm happy to accept a pull request :)

@mloughran
Owner

Now supported in master

@mloughran mloughran closed this Apr 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment