public function testZScan() { $this->redis->del('testZScan'); $key = 'testZScan'; $members = ['testScan', 'testScanHello', 'testScanHallo', 'testScanHaallo', 'testScanHoula', 'testScan2', 'testScanHello2', 'testScanHallo2', 'testScanHaallo2', 'testScanHoula2', 'testScan3', 'testScanHello3', 'testScanHallo3', 'testScanHaallo3', 'testScanHoula3']; foreach ($members as $member) { $this->redis->zAdd($key, 1.0, $member); } // a bit tricky to test, since we can't determine the outcome of a single iteration (or can we?) // so we just iterate until the iterator is exhausted and then compare the final results $iterator = 0; // we unroll the iteration here, to have better control over the involved values $result = $this->redis->zScan($key, $iterator); $this->assertNotEmpty($result); foreach ($members as $member) { $this->assertArrayHasKey($member, $result); } $this->assertSame(15, count($result)); $this->assertSame(0, $iterator); $smembers = $this->redis->zRange($key, 0, 100, true); ksort($smembers); ksort($result); $this->assertSame($smembers, $result); $result1 = $this->redis->zScan($key, $iterator, 'testScanH?llo', 20); $this->assertArrayHasKey('testScanHello', $result1); $this->assertArrayHasKey('testScanHallo', $result1); $this->assertEquals(2, count($result1)); $this->assertSame(0, $iterator); }
/** * Performs a background save. * * @return bool: TRUE in case of success, FALSE in case of failure. * If a save is already running, this command will fail and return FALSE. * @link http://redis.io/commands/bgsave * @example $redis->bgSave(); */ public function bgSave() { try { return $this->connection->bgSave(); } catch (Exception $e) { return $this->handleException($e, __FUNCTION__, func_get_args()); } }
public function disconnect($force = false) { if (!$this->connectWasCalled) { // if we never actually connected, we don't have to actually disconnect return true; } return $this->conn->disconnect($force); }
/** * @param Connection $connection */ public function __construct(Connection $connection) { $this->connection = $connection; $this->redis = $connection->getClient(); }
/** * This method uses the stored connection parameters to connect an instance. * * @param Connection $conn * @return bool */ protected function connectInstance(Connection $conn) { // connect() and pconnect() can throw exceptions, which we just want to treat as connection failures // TODO: really? can they? try { $res = $this->origPersistent ? $conn->pconnect($this->origHost, $this->origPort, $this->origTimeout) : $conn->connect($this->origHost, $this->origPort, $this->origTimeout); } catch (ConnectionError $e) { return false; } if ($this->origDbindex) { $res = $res && $conn->select($this->origDbindex); } return $res; }
/** * @param Connection $conn the wrapped redis connection * @param Logger $logger optional, a logger to log the invalid calls to */ public function __construct(Connection $conn, LoggerInterface $logger = null) { $this->conn = $conn; $this->redis = $conn->getClient(); $this->logger = $logger; }
/** * Performs a background save. * * @return bool: TRUE in case of success, FALSE in case of failure. * If a save is already running, this command will fail and return FALSE. * @link http://redis.io/commands/bgsave * @example $redis->bgSave(); */ public function bgSave() { $this->appendToLog('BGSAVE'); return $this->connection->bgSave(); }
public function __construct(Connection $conn, Time $time = null) { $this->connection = $conn; $this->redis = $this->connection->getClient(); $this->time = $time ?: new SystemTime(); }
/** * @param Connection $conn Connection of the wrapped instance */ public function __construct(Connection $conn) { $this->connection = $conn; $this->client = $conn->getClient(); }