/** * @param string $queue * @return QueueManager */ public function clearQueue($queue) { $this->redis->multi(); $this->redis->sRem(self::QUEUE_KEY, $queue); $this->redis->lTrim($this->formatQueueKey($queue), 1, 0); $this->redis->exec(); return $this; }
/** * @return bool */ public function close() { foreach ($this->ssIds as $key => $yes) { $this->client->unlock($key); } $this->ssIds = array(); return TRUE; }
/** * @param array $keys * @return array */ private function doMultiRead(array $keys) { $formatedKeys = array_map([$this, 'formatEntryKey'], $keys); $result = []; foreach ($this->client->send('mget', [$formatedKeys]) as $index => $stored) { $key = $keys[$index]; $result[$key] = $stored !== FALSE ? self::processStoredValue($key, $stored) : NULL; } return $result; }
/** * @param string $id * @return string */ protected function lock($id) { try { $key = $this->formatKey($id); $this->client->lock($key); $this->ssIds[$id] = $key; return $key; } catch (LockException $e) { throw new SessionHandlerException(sprintf('Cannot work with non-locked session id %s: %s', $id, $e->getMessage()), 0, $e); } }
/** * @param string $key * @throws LockException */ public function increaseLockTimeout($key) { if (!isset($this->keys[$key])) { return FALSE; } if ($this->keys[$key] <= time()) { throw LockException::durabilityTimedOut(); } $oldTimeout = $this->client->getSet($this->formatLock($key), $timeout = $this->calculateTimeout()); if ((int) $oldTimeout !== (int) $this->keys[$key]) { throw LockException::invalidDuration(); } $this->keys[$key] = $timeout; return TRUE; }
/** * @param string $key * @throws LockException */ public function increaseLockTimeout($key) { if (!isset($this->keys[$key])) { return FALSE; } if ($this->keys[$key] <= time()) { throw new LockException("Process ran too long. Increase lock duration, or extend lock regularly."); } $oldTimeout = $this->client->getSet($this->formatLock($key), $timeout = $this->calculateTimeout()); if ((int) $oldTimeout !== (int) $this->keys[$key]) { throw new LockException("Some rude client have messed up the lock duration."); } $this->keys[$key] = $timeout; return TRUE; }
/** * @param string $tag * * @return array */ private function tagEntries($tag) { return $this->client->sMembers($this->formatKey($tag, self::KEYS)) ?: []; }
/** * Verify, that redis is installed, working and has the right version. */ public function beforeCompile() { $config = $this->getConfig($this->defaults); if ($config['versionCheck'] && ($config['journal'] || $config['storage'] || $config['session'])) { $client = new RedisClient($config['host'], $config['port'], $config['database'], $config['timeout'], $config['auth']); $client->assertVersion(); $client->close(); } }
/** * Verify, that redis is installed, working and has the right version. */ public function beforeCompile() { foreach ($this->configuredClients as $config) { if (!$config['versionCheck']) { continue; } $client = new RedisClient($config['host'], $config['port'], $config['database'], $config['timeout'], $config['auth']); $client->assertVersion(); $client->close(); } }