/** * @param $hostUid * @param $key * @return null|UserText */ public function getTextsByUser($hostUid, $cached = true) { if ($cached) { $pattern = $this->buildKey($hostUid, '*', '*'); $prefix = $this->redis->getOptions()->prefix; $redisKeys = array_map(function ($redisKey) use($prefix) { if (substr($redisKey, 0, strlen($prefix)) == $prefix) { $redisKey = substr($redisKey, strlen($prefix)); } return $redisKey; }, $this->redis->keys($pattern)); if (count($redisKeys) > 0) { $result = array_combine($redisKeys, $this->redis->mget($redisKeys)); foreach ($result as $redisKey => $text) { list(, , $userId, , $key, $lang) = explode(':', $redisKey); $this->texts[$userId][$key][$lang] = $text; } } } if (!$cached || !isset($this->texts[$hostUid]) || !$this->texts[$hostUid]) { $this->texts[$hostUid] = $this->getTextsByHostFromMysql($hostUid); $mset = []; foreach ($this->texts[$hostUid] as $key => $langs) { foreach ($langs as $lang => $text) { $mset[$this->buildKey($hostUid, $key, $lang)] = $text; } } if ($mset) { $this->redis->mset($mset); } } return $this->texts[$hostUid]; }
/** * function that takes all keys from source redis, dumps them and imports to the new redis */ public function copy() { // retrieve all keys from source redis $keys = $this->source->keys('*'); $this->out("Processing %d REDIS keys ...", count($keys), true); $hundred = 0; $step = 0; foreach ($keys as $key) { // check for ignored keys and skip the key if it should be ignored foreach ($this->ignoredPrefixes as $ignoredPrefix) { if (strpos($key, $ignoredPrefix) !== false) { $this->out('.'); continue 2; // continue with the next key } } try { $ttl = max(0, (int) $this->source->ttl($key)); $serializedValue = $this->source->dump($key); $this->destination->restore($key, $ttl, $serializedValue); } catch (Exception $e) { $this->out(PHP_EOL . 'ERROR: ' . $key . PHP_EOL); } if ($step++ % 100 == 0) { $this->out(PHP_EOL . $hundred++ . ': '); } $this->out('o'); } $this->out(PHP_EOL . PHP_EOL); }
/** * @return array * @throws UnavailableException */ public function all() { try { return $this->client->keys('*'); } catch (ServerException $ex) { throw new UnavailableException($ex->getMessage()); } }
/** * @param $queueName */ private function getKeys($queueName, $useCache = false) { if (empty($this->keys) || !$useCache) { $this->keys = $this->redis->keys($this->getKeyPrefix($queueName) . '*'); } $prefix = (string) $this->redis->getOptions()->prefix; $this->keys = array_map(function ($key) use($prefix) { return preg_replace('/^' . $prefix . '/', '', $key); }, $this->keys); return $this->keys; }
/** * @param $key * * @return int */ public function removeWithName($key) { $result = 0; // se key ha l'asterisco, cancella tutte le chiavi che iniziano per il prefisso in $key if (strpos($key, '*') !== false) { foreach ($this->redis->keys($key) as $k) { $result += $this->redis->del($k); } } else { $result += $this->redis->del($key); } return $result; }
/** * @param string $providerPrefix * * @return bool */ public function invalidate($providerPrefix) { $keys = $this->client->keys($this->prefix . strtolower($providerPrefix) . '_*'); foreach ($keys as $key) { $this->client->del($key); } return true; }
/** * Returns an array of cache ids. * * @param string $prefix Optional id prefix * @return array An array of cache ids */ public function getIds($prefix = null) { if ($prefix) { return $this->_redis->keys($this->_getNamespacedId($prefix) . '*'); } else { return $this->_redis->keys($this->_getNamespacedId('*')); } }
/** * Get string values from storage using a valid key pattern * @param string $pattern the pattern * @return array an array of string values */ public function stringGetByPattern($pattern) { $keys = $this->_redis->keys($pattern); $values = []; foreach ($keys as $key) { $values[] = $this->stringRead($key); } return $values; }
/** * @param ModelInterface $model * @param array $ids * @return array */ public function getMany(ModelInterface $model, array $ids = []) { $table = $this->getTableName($model); $this->db->multiExec(); $data = []; if (empty($ids)) { $keys = $this->db->keys($table . ':*'); foreach ($keys as $key) { $json = $this->db->get($key); $data[] = $model->fromRaw(json_decode($json)); } } else { foreach ($ids as $id) { $data[] = $this->getById($model, $id); } } return $data; }
private function flushRedisCache($pattern) { $config = config('database.redis.' . config('cache.stores.redis.connection')); $client = new Redis(['scheme' => 'tcp', 'host' => $config['host'], 'port' => $config['port'], 'parameters' => ['password' => $config['password'], 'database' => $config['database']]]); $keys = $client->keys('collejo:criteria:' . str_replace('\\', '\\\\', $pattern) . ':*'); foreach ($keys as $key) { $client->del($key); } }
/** * {@inheritdoc} */ public function getIterator() { // TODO optimize the shit out of this crap $keys = $this->redis->keys('*'); $values = array_map(function ($key) { return $this->redis->get($key); }, $keys); $array = array_combine($keys, $values); return new ArrayIterator($array); }
/** * Delete all keys from redis */ protected function clearCache() { $this->logger->info('Clearing cache...'); $keys = $this->redis->keys('elogank.api.*'); if (null != $keys) { foreach ($keys as $key) { $this->redis->del($key); } } }
/** * @return array */ public function findSidsInRedis() { $prefix = (string) $this->redis->getOptions()->prefix; $pattern = $this->getKey(''); $prefixWithPattern = $prefix . $pattern; $keys = $this->redis->keys($pattern . '*'); $sids = array_map(function ($key) use($prefixWithPattern) { return str_replace($prefixWithPattern, '', $key); }, $keys); return $sids; }
public function getKeys($pattern = '*') { $prefix = null; if ($this->client->getOptions()->__isset("prefix")) { $prefix = $this->client->getOptions()->__get("prefix")->getPrefix(); } $keys = $this->client->keys($pattern); if ($prefix) { if (is_array($keys)) { for ($i = 0; $i < count($keys); $i++) { $keys[$i] = str_replace($prefix, '', $keys[$i]); } } else { $keys = str_replace($prefix, '', $keys); } } return $keys; }
/** * Get all keys within the namespace. * * @return array */ public function keys($namespace) { return $this->client->keys($namespace); }
protected function getCountOfSessionFiles() { return count($this->client->keys('wandu*')); }
public function getKeys($pattern) { $prefixedKeys = $this->_client->keys($pattern); $unprefixed = array_map(array($this, "stripPrefixFromKey"), $prefixedKeys); return $unprefixed; }
/** * ### Returns all failed jobs * * @return array */ public function getFailedJobs() { $prefix = Config::get('queue', 'failed_prefix'); $all = $this->connection->keys($prefix . '*'); return $all; }
/** * @param $pattern * @return mixed */ public function getKeys($pattern) { return $this->client->keys($pattern); }