instance method
get_multi
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
get_multi(*keys)
Retrieves multiple values from memcached in parallel, if possible.
The memcached protocol supports the ability to retrieve multiple keys in a single request. Pass in an array of keys to this method and it will:
-
map the key to the appropriate memcached server
-
send a single request to each server that has one or more key values
Returns a hash of values.
cache["a"] = 1 cache["b"] = 2 cache.get_multi "a", "b" # => { "a" => 1, "b" => 2 }
Note that get_multi assumes the values are marshalled.
Parameters
-
keysrest
Source
# File activesupport/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb, line 255
def get_multi(*keys)
raise MemCacheError, 'No active servers' unless active?
keys.flatten!
key_count = keys.length
cache_keys = {}
server_keys = Hash.new { |h,k| h[k] = [] }
# map keys to servers
keys.each do |key|
server, cache_key = request_setup key
cache_keys[cache_key] = key
server_keys[server] << cache_key
end
results = {}
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
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
end
return results
rescue TypeError => err
handle_error nil, err
end
Defined in activesupport/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb line 255
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in MemCache