lib/memcache.rb in memcache-client-1.7.8 vs lib/memcache.rb in memcache-client-1.8.0

- old
+ new

@@ -1,5 +1,6 @@ +# encoding: utf-8 $TESTING = defined?($TESTING) && $TESTING require 'socket' require 'thread' require 'zlib' @@ -293,15 +294,20 @@ # # cache["a"] = 1 # cache["b"] = 2 # cache.get_multi "a", "b" # => { "a" => 1, "b" => 2 } # - # Note that get_multi assumes the values are marshalled. + # Note that get_multi assumes the values are marshalled. You can pass + # in :raw => true to bypass value marshalling. + # + # cache.get_multi('a', 'b', ..., :raw => true) def get_multi(*keys) raise MemCacheError, 'No active servers' unless active? + opts = keys.last.is_a?(Hash) ? keys.pop : {} + keys.flatten! key_count = keys.length cache_keys = {} server_keys = Hash.new { |h,k| h[k] = [] } @@ -311,16 +317,16 @@ cache_keys[cache_key] = key server_keys[server] << cache_key end results = {} - + raw = opts[:raw] || false server_keys.each do |server, keys_for_server| keys_for_server_str = keys_for_server.join ' ' begin values = cache_get_multi server, keys_for_server_str values.each do |key, value| - results[cache_keys[key]] = Marshal.load value + results[cache_keys[key]] = raw ? value : Marshal.load(value) end rescue IndexError => e # Ignore this server and try the others logger.warn { "Unable to retrieve #{keys_for_server.size} elements from #{server.inspect}: #{e.message}"} if logger end