feat(redis): add scheduled cleanup command for Redis keys and enhance cleanup logic
This commit is contained in:
@@ -13,17 +13,20 @@ class CleanupRedis extends Command
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$prefix = config('database.redis.options.prefix');
|
||||
|
||||
$keys = Redis::connection()->keys('*:laravel*');
|
||||
collect($keys)->each(function ($key) use ($prefix) {
|
||||
$redis = Redis::connection('horizon');
|
||||
$keys = $redis->keys('*');
|
||||
$prefix = config('horizon.prefix');
|
||||
foreach ($keys as $key) {
|
||||
$keyWithoutPrefix = str_replace($prefix, '', $key);
|
||||
Redis::connection()->del($keyWithoutPrefix);
|
||||
});
|
||||
$type = $redis->command('type', [$keyWithoutPrefix]);
|
||||
|
||||
$queueOverlaps = Redis::connection()->keys('*laravel-queue-overlap*');
|
||||
collect($queueOverlaps)->each(function ($key) {
|
||||
Redis::connection()->del($key);
|
||||
});
|
||||
if ($type === 5) {
|
||||
$data = $redis->command('hgetall', [$keyWithoutPrefix]);
|
||||
$status = data_get($data, 'status');
|
||||
if ($status === 'completed') {
|
||||
$redis->command('del', [$keyWithoutPrefix]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ class Kernel extends ConsoleKernel
|
||||
}
|
||||
|
||||
// $this->scheduleInstance->job(new CleanupStaleMultiplexedConnections)->hourly();
|
||||
$this->scheduleInstance->command('cleanup:redis')->everyTenMinutes();
|
||||
|
||||
if (isDev()) {
|
||||
// Instance Jobs
|
||||
|
||||
Reference in New Issue
Block a user