hyperf / hyperf/cache

使用 Redis 驱动 deleteMultiple 出错

オープン
#5 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
PHP
スター
3
フォーク
4
PR マージ指標
30日以内にマージされた PR はありません

説明

在我使用 PhpSpreadsheet 生成电子表格时,我希望使用 Redis 作为缓存类。文档中指出,我可以直接从容器中获取 Psr\SimpleCache\CacheInterface 以得到一个符合PSR-16 的缓存类。按文档操作。
运行时程序抛出了警告错误:
```
PHP Warning: array_map(): Expected parameter 2 to be an array, object given in /Users/splitter/Project/zhentu-oa/vendor/hyperf/cache/src/Driver/RedisDriver.php on line 112

Warning: array_map(): Expected parameter 2 to be an array, object given in /Users/splitter/Project/zhentu-oa/vendor/hyperf/cache/src/Driver/RedisDriver.php on line 112
PHP Warning: Only arrays and Traversables can be unpacked in /Users/splitter/Project/zhentu-oa/vendor/hyperf/cache/src/Driver/RedisDriver.php on line 116
```
和致命错误:
```
Wrong parameter count for Redis::del()[193] in /Users/splitter/Project/zhentu-oa/vendor/hyperf/redis/src/RedisConnection.php
```
查阅源码,发现抛出Warning 的原因是 deleteMultiple 传入了一个 Generator 而非数组。
我尝试以下面方法解决:
```php
public function deleteMultiple($keys)
{
$cacheKeys = array_map(function ($key) {
return $this->getCacheKey($key);
}, array(...$keys));

return (bool) $this->redis->del(...$cacheKeys);
}
```
但是对于致命错误,我不得不重写 deleteMultiple 方法(虽然Redis 中的键的确被删除)
```php
public function deleteMultiple($keys)
{
foreach ($keys as $key) {
$this->redis->del($this->getCacheKey($key));
}
return true;
}
```
我不清楚是我的使用方法不正确或是驱动本身存在缺陷?

环境:
- hyperf/cache:2.2.15
- redis:5.0.6
- redis-ext:5.3.7

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Start with hyperf/cache/src/Driver/RedisDriver.php, especially deleteMultiple around lines 112 and 116, and reproduce the PSR-16 call with a Generator of keys. Check the reported array_map, unpacking, and Redis::del failures. Done means deleteMultiple accepts the documented input, removes the keys, and completes without warnings or a fatal error.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php, redis
領域
backend, databases
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。