getName(); } /** * Get client singleton. */ public static function getClient() { if (!isset(self::$_client)) { $settings = Settings::get('redis.connection', []); $settings += [ 'host' => self::REDIS_DEFAULT_HOST, 'port' => self::REDIS_DEFAULT_PORT, 'base' => self::REDIS_DEFAULT_BASE, 'password' => self::REDIS_DEFAULT_PASSWORD, ]; // If using replication, lets create the client appropriately. if (isset($settings['replication']) && $settings['replication'] === TRUE) { foreach ($settings['replication.host'] as $key => $replicationHost) { if (!isset($replicationHost['port'])) { $settings['replication.host'][$key]['port'] = self::REDIS_DEFAULT_PORT; } } self::$_client = self::getClientInterface()->getClient( $settings['host'], $settings['port'], $settings['base'], $settings['password'], $settings['replication.host']); } else { self::$_client = self::getClientInterface()->getClient( $settings['host'], $settings['port'], $settings['base'], $settings['password']); } } return self::$_client; } /** * Get specific class implementing the current client usage for the specific * asked core subsystem. * * @param string $system * One of the ClientFactory::IMPL_* constant. * @param string $clientName * Client name, if fixed. * * @return string * Class name, if found. * * @throws \Exception * If not found. */ public static function getClass($system, $clientName = NULL) { $className = $system . ($clientName ?: self::getClientName()); if (!class_exists($className)) { throw new \Exception($className . " does not exists"); } return $className; } /** * For unit testing only reset internals. */ static public function reset() { self::$_clientInterface = null; self::$_client = null; } }