本文整理汇总了PHP中Predis\Client::keys方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::keys方法的具体用法?PHP Client::keys怎么用?PHP Client::keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::keys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTextsByUser
/**
* @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];
}
示例2: copy
/**
* 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);
}
示例3: all
/**
* @return array
* @throws UnavailableException
*/
public function all()
{
try {
return $this->client->keys('*');
} catch (ServerException $ex) {
throw new UnavailableException($ex->getMessage());
}
}
示例4: getKeys
/**
* @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;
}
示例5: removeWithName
/**
* @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;
}
示例6: invalidate
/**
* @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;
}
示例7: getIds
/**
* 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('*'));
}
}
示例8: stringGetByPattern
/**
* 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;
}
示例9: getMany
/**
* @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;
}
示例10: flushRedisCache
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);
}
}
示例11: getIterator
/**
* {@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);
}
示例12: clearCache
/**
* 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);
}
}
}
示例13: findSidsInRedis
/**
* @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;
}
示例14: getKeys
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;
}
示例15: keys
/**
* Get all keys within the namespace.
*
* @return array
*/
public function keys($namespace)
{
return $this->client->keys($namespace);
}