views:

269

answers:

2

Problem

I'm getting the error:

key too long "rack:session:BAh7...."
/usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/memcache-client-1.8.5/lib/memcache.rb:703:in `get_server_for_key'
/usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/memcache-client-1.8.5/lib/memcache.rb:920:in `request_setup'
/usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/memcache-client-1.8.5/lib/memcache.rb:885:in `with_server'

When I looked at memcache-client-1.8.5/lib/memcache.rb:703

def get_server_for_key(key, options = {})
  raise ArgumentError, "illegal character in key #{key.inspect}" if key =~ /\s/
  raise ArgumentError, "key too long #{key.inspect}" if key.length > 250
  ...
end

Also according http://code.google.com/p/memcached/wiki/FAQ#What_is_the_maxiumum_key_length?_(250_bytes) the max length is 250 bytes.

Since this is production and is pretty hard to replicate this error, i figured i can ask here if any one had the same issue before.

Question 1: Can I remove the statement from the memcache-client?

Question 2: Is there any way to reduced the key size in rails? I'm using the below in my production.rb

config.action_controller.session_store = :mem_cache_store  
A: 

That limit seems to be imposed by memcached itself, not Ruby, so removing that statement will not help you. The memcached documentation suggests that if your key size is longer than 250 bytes, you're probably doing something wrong anyways.

Matti Virkkunen
simply changed the session_store to use :mem_cached_store instead of cookie.config.action_controller.session_store = :mem_cache_store
Greg
A: 
key too long "rack:session:BAh7...."

Are you dumping your entire session into the cache as a key? If you are manually adding to the cache, please post that code.

jdl
Not manually adding to the cached. I configured rails to use memchaced, in my production.rb config.action_controller.session_store = :mem_cache_store
Greg