BigTablet.com Blog

May 18, 2009

Rails 2.3 and Memcache Server Hashes

Filed under: Ruby & Rails — Tags: — ciddennis @ 3:39 pm

So at another project I have situation where I have to share some information in memcache with a java client.   We use a cluster of about 5 memcachd servers to do this data sharing.    This has worked fine for a number of months but when I recently upgraded to rails 2.3 I found it would no longer find right servers.   When I looked in to it more I found that the memcache_client library changed its servers selection algorithm to use something called consistent hashing.  Anyway now the default Rails.cache.fetch does not work.  So while I look for a java client that uses the same server selection algorithm I just did this:


def get_memcach_token(mem_cache_id)
Rails.cache.addresses.each { |address|
value = MemCache.new([address]).get(mem_cache_id,{:raw => true})
return value if value
}
nil
end

The other option is to go back to memcache_client 1.5.  But then you are going to be stuck there forever.

2 Comments »

  1. may I publish this under your name at sencaw?

    Comment by sencaw — June 7, 2009 @ 5:22 pm

    • Sure, I talked with the developer of memcach client for ruby and he said there is no spec for how the hash for the memcach key is generated. The old way just happened to match up to the java client.
      So for now I will keep my change.

      Comment by ciddennis — June 7, 2009 @ 7:52 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.