code: def _check_key(key, allow_unicode_keys, key_prefix=b''):
      
      if allow_unicode_keys:
          if isinstance(key, six.text_type):
              key = key.encode('utf8')
      elif isinstance(key, VALID_STRING_TYPES):
          try:
              if isinstance(key, bytes):
                  key = key.decode().encode('ascii')
              else:
                  key = key.encode('ascii')
          except (UnicodeEncodeError, UnicodeDecodeError):
              raise MemcacheIllegalInputError("Non-ASCII key: '%r'" % key)
  
      key = key_prefix + key
      parts = key.split()
  
      if len(key) > 250:
          raise MemcacheIllegalInputError("Key is too long: '%r'" % key)
      # second statement catches leading or trailing whitespace
      elif len(parts) > 1 or parts[0] != key:
          raise MemcacheIllegalInputError("Key contains whitespace: '%r'" % key)
      elif b'\00' in key:
          raise MemcacheIllegalInputError("Key contains null: '%r'" % key)
  
      return key
docs: Checks key and add key_prefix.