%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /dom645759/wp-content/mu-plugins/object-cache-pro/src/Connections/
Upload File :
Create Path :
Current File : //dom645759/wp-content/mu-plugins/object-cache-pro/src/Connections/RelaySentinelsConnection.php

<?php
/**
 * Copyright © 2019-2026 Rhubarb Tech Inc. All Rights Reserved.
 *
 * The Object Cache Pro Software and its related materials are property and confidential
 * information of Rhubarb Tech Inc. Any reproduction, use, distribution, or exploitation
 * of the Object Cache Pro Software and its related materials, in whole or in part,
 * is strictly forbidden unless prior permission is obtained from Rhubarb Tech Inc.
 *
 * In addition, any reproduction, use, distribution, or exploitation of the Object Cache Pro
 * Software and its related materials, in whole or in part, is subject to the End-User License
 * Agreement accessible in the included `LICENSE` file, or at: https://objectcache.pro/eula
 */

declare(strict_types=1);

namespace RedisCachePro\Connections;

use Throwable;
use Relay\Sentinel;

use RedisCachePro\Clients\RelaySentinel;
use RedisCachePro\Connectors\RelayConnector;
use RedisCachePro\Configuration\Configuration;
use RedisCachePro\Exceptions\ConnectionException;

use function RedisCachePro\log;

class RelaySentinelsConnection extends RelayReplicatedConnection implements ConnectionInterface
{
    use Concerns\SentinelsConnection;

    /**
     * The current Sentinel node.
     *
     * @var string
     */
    protected $sentinel;

    /**
     * Holds all Sentinel states and URLs.
     *
     * If the state is `null` no connection has been established.
     * If the state is `false` the connection failed or a timeout occurred.
     * If the state is a `RelaySentinel` object it's the current Sentinel node.
     *
     * @var array<string, \RedisCachePro\Clients\RelaySentinel|null|false>
     */
    protected $sentinels;

    /**
     * Create a new PhpRedis Sentinel connection.
     *
     * @param  \RedisCachePro\Configuration\Configuration  $config
     */
    public function __construct(Configuration $config)
    {
        $this->config = $config;

        foreach ($config->sentinels as $sentinel) {
            $this->sentinels[$sentinel] = null;
        }

        if (RelayConnector::supports('get-meta')) {
            $this->supportsGetWithMeta = true;
        }

        $this->connectToSentinels();
    }

    /**
     * Returns the current Sentinel connection.
     *
     * @return \RedisCachePro\Clients\RelaySentinel|false|null
     */
    public function sentinel()
    {
        return $this->sentinels[$this->sentinel];
    }

    /**
     * Establish a connection to the given Redis Sentinel and its primary and replicas.
     *
     * @param  string  $url
     * @return void
     */
    protected function establishConnections(string $url)
    {
        $config = clone $this->config;
        $config->setUrl($url);

        $persistentId = '';

        $arguments = [
            $config->host,
            $config->port,
            $config->timeout,
            $persistentId,
            $config->retry_interval,
            $config->read_timeout,
        ];

        if ($config->password) {
            $arguments[] = $config->username
                ? [$config->username, $config->password]
                : $config->password;
        }

        $this->sentinels[$url] = new RelaySentinel(function () use ($arguments) {
            return new Sentinel(...$arguments);
        }, $config->tracer);

        $this->discoverPrimary();
        $this->discoverReplicas();
    }

    /**
     * Discovers and connects to the Sentinel primary.
     *
     * @return void
     */
    protected function discoverPrimary()
    {
        if (! $sentinel = $this->sentinel()) {
            throw new ConnectionException(sprintf(
                'Unable to discover sentinel primary for `%s` (%s)',
                $this->sentinel,
                gettype($this->sentinel)
            ));
        }

        if (! $primary = $sentinel->getMasterAddrByName($this->config->service)) {
            throw new ConnectionException("Failed to retrieve sentinel primary of `{$this->sentinel}`");
        }

        $config = clone $this->config;
        $config->setHost($primary[0]);
        $config->setPort($primary[1]);

        $connection = RelayConnector::connectToInstance($config);

        /** @var array<int, mixed> $role */
        $role = $connection->role();

        if (($role[0] ?? null) !== 'master') {
            throw new ConnectionException(sprintf(
                'Sentinel `%s` returned primary `%s` but its role is `%s`',
                $this->sentinel,
                "{$primary[0]}:{$primary[1]}",
                $role[0] ?? 'unknown'
            ));
        }

        $this->primary = $connection;
        $this->client = $connection->client();
    }

    /**
     * Discovers and connects to the Sentinel replicas.
     *
     * @return void
     */
    protected function discoverReplicas()
    {
        if (! $sentinel = $this->sentinel()) {
            throw new ConnectionException(sprintf(
                'Unable to discover sentinel replicas for `%s` (%s)',
                $this->sentinel,
                gettype($this->sentinel)
            ));
        }

        if (! $replicas = $sentinel->slaves($this->config->service)) {
            throw new ConnectionException("Failed to discover Sentinel replicas of `{$this->sentinel}`");
        }

        $this->replicas = [];

        foreach ($replicas as $replica) {
            if (($replica['role-reported'] ?? '') !== 'slave') {
                continue;
            }

            $config = clone $this->config;
            $config->setHost($replica['ip']);
            $config->setPort($replica['port']);

            try {
                $this->replicas[$replica['name']] = RelayConnector::connectToInstance($config);
            } catch (Throwable $error) {
                log('warning', $error->getMessage());
            }
        }
    }
}

Zerion Mini Shell 1.0
https://louisvillegop.com/sitemap257.xml 2026-12-01 https://louisvillegop.com/sitemap129.xml 2026-12-01 https://louisvillegop.com/sitemap396.xml 2026-12-01 https://louisvillegop.com/sitemap404.xml 2026-12-01 https://louisvillegop.com/sitemap723.xml 2026-12-01 https://louisvillegop.com/sitemap930.xml 2026-12-01 https://louisvillegop.com/sitemap947.xml 2026-12-01 https://louisvillegop.com/sitemap737.xml 2026-12-01 https://louisvillegop.com/sitemap369.xml 2026-12-01 https://louisvillegop.com/sitemap332.xml 2026-12-01 https://louisvillegop.com/sitemap560.xml 2026-12-01 https://louisvillegop.com/sitemap910.xml 2026-12-01 https://louisvillegop.com/sitemap909.xml 2026-12-01 https://louisvillegop.com/sitemap938.xml 2026-12-01 https://louisvillegop.com/sitemap519.xml 2026-12-01 https://louisvillegop.com/sitemap394.xml 2026-12-01 https://louisvillegop.com/sitemap159.xml 2026-12-01 https://louisvillegop.com/sitemap593.xml 2026-12-01 https://louisvillegop.com/sitemap860.xml 2026-12-01 https://louisvillegop.com/sitemap849.xml 2026-12-01 https://louisvillegop.com/sitemap557.xml 2026-12-01 https://louisvillegop.com/sitemap150.xml 2026-12-01 https://louisvillegop.com/sitemap410.xml 2026-12-01 https://louisvillegop.com/sitemap826.xml 2026-12-01 https://louisvillegop.com/sitemap590.xml 2026-12-01 https://louisvillegop.com/sitemap333.xml 2026-12-01 https://louisvillegop.com/sitemap758.xml 2026-12-01 https://louisvillegop.com/sitemap473.xml 2026-12-01 https://louisvillegop.com/sitemap232.xml 2026-12-01 https://louisvillegop.com/sitemap121.xml 2026-12-01 https://louisvillegop.com/sitemap354.xml 2026-12-01 https://louisvillegop.com/sitemap856.xml 2026-12-01 https://louisvillegop.com/sitemap267.xml 2026-12-01 https://louisvillegop.com/sitemap427.xml 2026-12-01 https://louisvillegop.com/sitemap46.xml 2026-12-01 https://louisvillegop.com/sitemap691.xml 2026-12-01 https://louisvillegop.com/sitemap571.xml 2026-12-01 https://louisvillegop.com/sitemap116.xml 2026-12-01 https://louisvillegop.com/sitemap1000.xml 2026-12-01 https://louisvillegop.com/sitemap44.xml 2026-12-01 https://louisvillegop.com/sitemap483.xml 2026-12-01 https://louisvillegop.com/sitemap431.xml 2026-12-01 https://louisvillegop.com/sitemap499.xml 2026-12-01 https://louisvillegop.com/sitemap178.xml 2026-12-01 https://louisvillegop.com/sitemap695.xml 2026-12-01 https://louisvillegop.com/sitemap733.xml 2026-12-01 https://louisvillegop.com/sitemap256.xml 2026-12-01 https://louisvillegop.com/sitemap82.xml 2026-12-01 https://louisvillegop.com/sitemap853.xml 2026-12-01 https://louisvillegop.com/sitemap606.xml 2026-12-01 https://louisvillegop.com/sitemap251.xml 2026-12-01 https://louisvillegop.com/sitemap744.xml 2026-12-01 https://louisvillegop.com/sitemap772.xml 2026-12-01 https://louisvillegop.com/sitemap79.xml 2026-12-01 https://louisvillegop.com/sitemap969.xml 2026-12-01 https://louisvillegop.com/sitemap244.xml 2026-12-01 https://louisvillegop.com/sitemap866.xml 2026-12-01 https://louisvillegop.com/sitemap991.xml 2026-12-01 https://louisvillegop.com/sitemap879.xml 2026-12-01 https://louisvillegop.com/sitemap271.xml 2026-12-01 https://louisvillegop.com/sitemap530.xml 2026-12-01 https://louisvillegop.com/sitemap179.xml 2026-12-01 https://louisvillegop.com/sitemap727.xml 2026-12-01 https://louisvillegop.com/sitemap395.xml 2026-12-01 https://louisvillegop.com/sitemap277.xml 2026-12-01 https://louisvillegop.com/sitemap955.xml 2026-12-01 https://louisvillegop.com/sitemap563.xml 2026-12-01 https://louisvillegop.com/sitemap189.xml 2026-12-01 https://louisvillegop.com/sitemap221.xml 2026-12-01 https://louisvillegop.com/sitemap754.xml 2026-12-01