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

mcorner opened this Issue Nov 1, 2012 · 2 comments

2 participants


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:\/\/\//
url = URI(uri || ENV["REDIS_URL"] || "redis://")
Client.new(url.host, url.port, url.password, url.path[1..-1])

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


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


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