取得Laravel中快取中的所有Redis鍵的方法
P粉986860950
P粉986860950 2024-02-17 19:20:02
0
1
376

Laravel 中的快取外觀似乎不允許您取得目前快取在 Redis 中的所有按鍵。

我想建立一個端點,以便我可以檢索此資訊並了解我的條目是否正常運作。

我嘗試使用 Redis 外觀,但使用以下命令及其各自的錯誤沒有成功

Redis::keys("*");

"Cannot use 'KEYS' with redis-cluster."


Redis::scan("cursor");

"Cannot use 'SCAN' with redis-cluster."

P粉986860950
P粉986860950

全部回覆(1)
P粉627027031

在Redis、叢集中,如果你有很多key,建議掃描而不是key。 但是,您應該正確使用它。嘗試使用這種方式。

use Illuminate\Support\Facades\Redis;

$cursor = '0'; // Start with initial cursor

do {
    // Scan for keys with current cursor
    list($cursor, $keys) = Redis::scan($cursor);

    foreach ($keys as $key) {
      echo "Key: $key\n";
   }
} while ($cursor !== '0'); // Continue scanning until cursor is '0'

參考: Laravel 和 redis 掃描

#
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!