Bugfixings for getAllKeys()

This commit is contained in:
Philipp Holzer 2018-10-07 22:14:05 +02:00
parent 8491f8660f
commit 7da6da6666
No known key found for this signature in database
GPG Key ID: 517BE60E2CE5C8A5
5 changed files with 8 additions and 7 deletions

View File

@ -53,7 +53,7 @@ class Cache extends \Friendica\BaseObject
* *
* @param string $prefix Prefix of the keys (optional) * @param string $prefix Prefix of the keys (optional)
* *
* @return array|null Null if the driver doesn't support this feature * @return array Empty if the driver doesn't support this feature
*/ */
public static function getAllKeys($prefix = null) public static function getAllKeys($prefix = null)
{ {

View File

@ -21,18 +21,18 @@ class DatabaseCacheDriver extends AbstractCacheDriver implements ICacheDriver
if (empty($prefix)) { if (empty($prefix)) {
$where = ['`expires` >= ?', DateTimeFormat::utcNow()]; $where = ['`expires` >= ?', DateTimeFormat::utcNow()];
} else { } else {
$where = ['`expires` >= ? AND k LIKE CONCAT(?, \'%\')', DateTimeFormat::utcNow(), $prefix]; $where = ['`expires` >= ? AND `k` LIKE CONCAT(?, \'%\')', DateTimeFormat::utcNow(), $prefix];
} }
$stmt = DBA::select('cache', ['k'], $where); $stmt = DBA::select('cache', ['k'], $where);
$list = []; $keys = [];
while ($key = DBA::fetch($stmt)) { while ($key = DBA::fetch($stmt)) {
array_push($list, $key['k']); array_push($keys, $key['k']);
} }
DBA::close($stmt); DBA::close($stmt);
return $list; return $keys;
} }
/** /**

View File

@ -16,7 +16,7 @@ interface ICacheDriver
* *
* @param string prefix optional a prefix to search * @param string prefix optional a prefix to search
* *
* @return array|null Null if it isn't supported by the cache driver * @return array Empty if it isn't supported by the cache driver
*/ */
public function getAllKeys($prefix = null); public function getAllKeys($prefix = null);

View File

@ -65,7 +65,7 @@ class MemcachedCacheDriver extends AbstractCacheDriver implements IMemoryCacheDr
return $this->filterArrayKeysByPrefix($keys, $prefix); return $this->filterArrayKeysByPrefix($keys, $prefix);
} else { } else {
logger('Memcached \'getAllKeys\' failed with ' . $this->memcached->getResultMessage(), LOGGER_ALL); logger('Memcached \'getAllKeys\' failed with ' . $this->memcached->getResultMessage(), LOGGER_ALL);
return null; return [];
} }
} }

View File

@ -116,6 +116,7 @@ HELP;
$count = 0; $count = 0;
foreach ($keys as $key) { foreach ($keys as $key) {
$this->out($key); $this->out($key);
$count++;
} }
$this->out($count . ' keys found'); $this->out($count . ' keys found');