Closed mcorner closed 11 years ago
If you clean this up I'm happy to accept a pull request :)
Now supported in master
How should the DB be selected when using a file socket? I found the "it's not possible to set the db or password - use initialize instead" part in the comments, but… which #initialize
? And how?
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