public function testGetNodes() { $servers = explode(',', $_ENV['DISQUE_SERVERS']); try { $pool = new Pool($servers); } catch (ConnectException $e) { $this->markTestSkipped($e->getMessage()); } $this->assertSame($servers, $pool->getNodeUrls()); }
/** * Connect to a random node in the (cached) node list. * * @return DefaultStream Stream to a connected node. * * @throws ConnectException */ public function connect() { $key = array_reduce($this->nodeUrls, function ($current, $prev) { return md5($current . $prev); }, ''); // prefer cached results $hit = $this->cache->get($key); if (!empty($hit)) { $this->log->notice('nodelist retrieved from cache', ['nodes' => $hit, 'key' => $key]); $this->nodeUrls = $hit; } $stream = parent::connect(); // update cache if (empty($hit)) { $this->updateNodes($key, $stream); } return $stream; }