0

It appears that the Cache facade in Laravel doesn't allow you to get all the keys that are currently being cached in Redis.

I want to create an endpoint so I can retrieve this info and know if my entries are working properly.

I tried using the Redis facade with no success using the following commands and their respective errors

Redis::keys("*");

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


Redis::scan("cursor");

"Cannot use 'SCAN' with redis-cluster."
Drew Gallagher
  • 442
  • 1
  • 12

1 Answers1

-1

In Redis, cluster, scan is recommended over key if you have lots of keys. However, you should use it correctly. Try using this way.

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'

Reference: Laravel and redis scan

Ali Raza
  • 155
  • 7