vendor/bundle/ruby/1.8/gems/Ruby-MemCache-0.0.1/lib/memcache.rb
### Fetch the values corresponding to the given +keys+ from the cache and
### return them as a Hash.
Fetch the values corresponding to the given +keys+ from the cache and
return them as a Hash.
Fetch the values corresponding to the given + keys + from the cache and return them as a Hash .
def fetch( type, *keys )
		map = Hash::new {|hsh,key| hsh[key] = 'get'}
		cachekeys = {}
		res = {}
		self.add_stat( type ) {
			keys.each do |key|
				svr = self.get_server( key )
				ckey = self.make_cache_key( key )
				cachekeys[ ckey ] = key
				map[ svr ] << " " + ckey
			end
			self.send( map, true ) do |svr, reply|
				while reply.sub!( /^VALUE (\S+) (\d+) (\d+)\r\n/, '' )
					ckey, flags, len = $1, $2.to_i, $3.to_i
					data = reply.slice!( 0, len + 2 ) 
					rval = self.restore( data[0,len], flags )
					res[ cachekeys[ckey] ] = rval
				end
				unless reply == "END" + CRLF
					raise MemCacheError, "Malformed reply fetched from %p: %p" %
						[ svr, rval ]
				end
			end
		}
		return res
	end
def fetch ( type , * keys ) map = Hash :: new { | hsh , key | hsh [ key ] = 'get' } cachekeys = { } res = { } self . add_stat ( type ) { keys . each do | key | svr = self . get_server ( key ) ckey = self . make_cache_key ( key ) cachekeys [ ckey ] = key map [ svr ] << " " + ckey end self . send ( map , true ) do | svr , reply | while reply . sub! ( / ^VALUE ( \S +) ( \d +) ( \d +) \r \n / , '' ) ckey , flags , len = $1 , $2 . to_i , $3 . to_i data = reply . slice! ( 0 , len + 2 ) rval = self . restore ( data [ 0 , len ] , flags ) res [ cachekeys [ ckey ] ] = rval end unless reply == "END" + CRLF raise MemCacheError , "Malformed reply fetched from %p: %p" % [ svr , rval ] end end } return res end
Fetch the values corresponding to the given +keys+ from the cache and
return them as a Hash.
Fetch the values corresponding to the given + keys + from the cache and return them as a Hash .
# Make a hash to hold servers => commands for the keys to be fetched, # and one to match cache keys to user keys. # Map the key's server to the command to fetch its value # Send the commands and map the results hash into the return hash # Iterate over the replies, stripping first the 'VALUE # <cachekey> <flags> <len>' line with a regexp and then the data # line by length as specified by the VALUE line. # Restore compressed and thawed values that require it. # + CRLF
type
keys