src/Adapters/Memcached.php
protected function encode($key)
    {
        $regex = '/[^\x21\x22\x24\x26-\x39\x3b-\x7e]+/';
        $key = preg_replace_callback($regex, function ($match) {
            return rawurlencode($match[0]);
        }, $key);

        if (strlen($key) > 255) {
            throw new InvalidKey(
                "Invalid key: $key. Encoded Memcached keys can not exceed 255 chars."
            );
        }

        return $key;
    }
protected function encode($key)
    {
        $regex = '/[^\x21\x22\x24\x26-\x39\x3b-\x7e]+/';
        $key = preg_replace_callback($regex, function ($match) {
            return rawurlencode($match[0]);
        }, $key);

        if (strlen($key) > 255) {
            throw new InvalidKey(
                "Invalid key: $key. Encoded Memcached keys can not exceed 255 chars."
            );
        }

        return $key;
    }
protected function encode ( $ key ) { $ regex = '/[^\x21\x22\x24\x26-\x39\x3b-\x7e]+/' ; $ key = preg_replace_callback ( $ regex , function ( $ match ) { return rawurlencode ( $ match [ 0 ] ) ; } , $ key ) ; if ( strlen ( $ key ) > 255 ) { throw new InvalidKey ( "Invalid key: $key. Encoded Memcached keys can not exceed 255 chars." ) ; } return $ key ; }
Encode a key for use on the wire inside the memcached protocol.

We encode spaces and line breaks to avoid protocol errors. We encode
the other control characters for compatibility with libmemcached
verify_key. We leave other punctuation alone, to maximise backwards
compatibility.

@see https://github.com/wikimedia/mediawiki/commit/be76d869#diff-75b7c03970b5e43de95ff95f5faa6ef1R100
@see https://github.com/wikimedia/mediawiki/blob/master/includes/libs/objectcache/MemcachedBagOStuff.php#L116

@param string $key

@return string

@throws InvalidKey
Encode a key for use on the wire inside the memcached protocol .