public function checkConnectionDetails($host, $port, $timeout, $password) { $redis = new Redis(); $redis->setConfig($host, $port, $timeout, $password); if (!$redis->testConnection()) { throw new \Exception('Connection to Redis failed. Please verify Redis host and port'); } $version = $redis->getServerVersion(); if (version_compare($version, '2.8.0') < 0) { throw new \Exception('At least Redis server 2.8.0 is required'); } }
private static function makeBackendFromSettings(Settings $settings) { $host = $settings->redisHost->getValue(); $port = $settings->redisPort->getValue(); $timeout = $settings->redisTimeout->getValue(); $password = $settings->redisPassword->getValue(); $database = $settings->redisDatabase->getValue(); $redis = new Queue\Backend\Redis(); $redis->setConfig($host, $port, $timeout, $password); $redis->setDatabase($database); return $redis; }
private function disconnect() { if ($this->isConnected()) { $this->redis->close(); } $this->redis = null; }
public function expireLock($ttlInSeconds) { if ($ttlInSeconds > 0 && $this->lockValue) { $success = $this->backend->expireIfKeyHasValue($this->lockKey, $this->lockValue, $ttlInSeconds); if (!$success) { $value = $this->backend->get($this->lockKey); $message = sprintf('Failed to expire key %s (%s / %s).', $this->lockKey, $this->lockValue, (string) $value); if ($value === false) { Common::printDebug($message . ' It seems like the key already expired as it no longer exists.'); } elseif (!empty($value) && $value == $this->lockValue) { Common::printDebug($message . ' We still have the lock but for some reason it did not expire.'); } elseif (!empty($value)) { Common::printDebug($message . ' It seems to be locked by another queue.'); } else { Common::printDebug($message . ' Failed to expire key.'); } return false; } return true; } return false; }
public function test_checkConnectionDetails_shouldFailIfPortIsWrong() { $this->redis->setConfig('127.0.0.1', 6370, 0.2, null); $success = $this->redis->testConnection(); $this->assertFalse($success); }
public function markRequestSetsAsProcessed() { $this->backend->removeFirstXValuesFromList($this->key, $this->numRequestsToProcessInBulk); }