def insert(self, val):     
      """\
      Inserts a value and returns a :class:`Pair <Pair>`.

      If the generated key exists or memcache cannot store it, a 
      :class:`KeyInsertError <shorten.KeyInsertError>` is raised (or a
      :class:`TokenInsertError <shorten.TokenInsertError>` if a token
      exists or cannot be stored).      
      """

      key, token, formatted_key, formatted_token = self.next_formatted_pair()

      if self.has_key(key):
         raise KeyInsertError(key)

      if self.has_token(token):
         raise TokenInsertError(token)

      # Memcache is down or read-only

      if not self._mc.add(formatted_key, (val, token)):
         raise KeyInsertError(key, 'key could not be stored')

      if not self._mc.add(formatted_token, key):
         raise TokenInsertError(token, 'token could not be stored')

      return Pair(key, token)