    # File lib/active_support/vendor/memcache-client-1.6.5/memcache.rb, line 281
      def set(key, value, expiry = 0, raw = false)
        raise MemCacheError, "Update of readonly cache" if @readonly
        with_server(key) do |server, cache_key|

          value = Marshal.dump value unless raw
          logger.debug { "SET #{key} to #{server.inspect}: #{value ? value.to_s.size : 'nil'}" } if logger

          data = value.to_s
          raise MemCacheError, "Value too large, memcached can only store 1MB of data per key" if data.size > ONE_MB

          command = "set #{cache_key} 0 #{expiry} #{data.size}\r\n#{data}\r\n"

          with_socket_management(server) do |socket|
            socket.write command
            result = socket.gets
            raise_on_error_response! result

            if result.nil?
              server.close
              raise MemCacheError, "lost connection to #{server.host}:#{server.port}"
            end

            result
          end
        end
      end