Method: Memcached#get

Defined in:
lib/memcached/memcached.rb

#get(keys, decode = true) ⇒ Object

Gets a key’s value from the server. Accepts a String key or array of String keys.

Also accepts a decode value, which defaults to true. Set decode to false if you want the value to be returned directly as a String. Otherwise it will be assumed to be an encoded Ruby object and decoded.

If you pass a String key, and the key does not exist on the server, Memcached::NotFound will be raised. If you pass an array of keys, memcached’s multiget mode will be used, and a hash of key/value pairs will be returned. The hash will contain only the keys that were found.

The multiget behavior is subject to change in the future; however, for multiple lookups, it is much faster than normal mode.

Note that when you rescue Memcached::NotFound exceptions, you should use a the block rescue syntax instead of the inline syntax. Block rescues are very fast, but inline rescues are very slow.



500
501
502
503
504
505
506
507
508
509
510
511
# File 'lib/memcached/memcached.rb', line 500

def get(keys, decode=true)
  if keys.is_a? Array
    multi_get(keys, decode).first
  else
    single_get(keys, decode).first
  end
rescue => e
  tries ||= 0
  raise unless tries < options[:exception_retry_limit] && should_retry(e)
  tries += 1
  retry
end