protected function parsePersistentId(array $connections, OptionsBag $options, OptionsBag $sessionOptions)
    {
        // Try based on save_path.
        $savePath = $sessionOptions['save_path'];
        $savePath = trim($savePath); // Just in case.
        if ($savePath) {
            // v3.0 uses save path for ID (from what I can tell)
            $persistentId = 'memc-session:' . $savePath;

            // v2.0 uses "PERSISTENT=foo servers", so parse that.
            if (strpos($savePath, 'PERSISTENT=') === 0) {
                $end = strpos($savePath, ' ');
                if ($end === false) {
                    throw new InvalidArgumentException('Unable to parse session save_path');
                }

                $persistentId = substr($savePath, 11, $end - 11);
            }

            return $persistentId;
        }

        // Try based on specified value in options.
        if ($options->has('persistent_id')) {
            return $options['persistent_id'];
        }

        // Determine automatically.
        $hashParts = [];

        foreach ($connections as $conn) {
            $hashParts[] = sprintf('%s:%s:%s', $conn['host'], $conn['port'], $conn['weight']);
        }
        foreach ($options as $key => $value) {
            $hashParts[] = $key . ':' . $value;
        }

        $hash = hash('sha256', implode(',', $hashParts));

        return $hash;
    }