I've just spent a few minutes banging my head against a wall trying to get Ruby (1.9.2) to work with Memcache, via the Dalli Ruby gem, on my Mac.
Following some pretty simple, clear directions I found via the web, I did this:
brew install memcached
...then
gem install dalli
...then I ran the memcache server:
memcached -vv
~> irb
ruby-1.9.2-p290 :001 > require 'dalli'
=> true
ruby-1.9.2-p290 :002 > cache = Dalli::Client.new
=> #<Dalli::Client:0x00000101969518 @servers="127.0.0.1:11211", @options={:expires_in=>0}, @ring=nil>
ruby-1.9.2-p290 :003 > cache.set('a','1')
I, [2012-04-03T15:44:01.940036 #52987] INFO -- : 127.0.0.1:11211 failed (count: 0)
Dalli::RingError: No server available
from /Users/lglenn2/.rvm/gems/ruby-1.9.2-p290/gems/dalli-2.0.2/lib/dalli/ring.rb:45:in `server_for_key'
from /Users/lglenn2/.rvm/gems/ruby-1.9.2-p290/gems/dalli-2.0.2/lib/dalli/client.rb:249:in `perform'
from /Users/lglenn2/.rvm/gems/ruby-1.9.2-p290/gems/dalli-2.0.2/lib/dalli/client.rb:118:in `set'
from (irb):3
from /Users/lglenn2/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
ruby-1.9.2-p290 :004 >
My standard tactic of trying that over and over again failed to produce a different result. I then moved on to fiddling with ports, turning off UDP, nmap'ming my machine, all to no avail.
Then I noticed that the Dalli docs pretty clearly state that you need memcached 1.4+. They also pretty clearly say that Mac OSX Snow Leopard ships with 1.2.8. Then I did a which memcached
, and saw that I'd been running the memcached that's in /usr/bin, not the memcached that homebrew installs, which is in /usr/local/bin.
Oops!
Run the server like this:
/usr/local/bin/memcached -vv
...and you're good to go.
I was at my wit's end with this, 2 years later... thanks!