deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

How Redis allkeys-lru eviction can silently drop Laravel queue jobs

A dev.to post explains how Redis's allkeys-lru policy can silently evict Laravel queue lists, with no error or failed-job record. It also covers a cache:clear flush trap and a read-only package that audits both risks.

How Redis allkeys-lru eviction can silently drop Laravel queue jobs

How jobs vanish without a trace

According to a post on dev.to by Amjad Iqbal, a widespread Laravel deployment pattern — one Redis instance serving the cache, the queue and the session store — hides a failure mode in which queued jobs disappear without an error, a failed-job record or a log line.

The cause is Redis's memory configuration. When the server runs with maxmemory-policy allkeys-lru, Redis is free to remove any key it picks once memory runs out. Laravel keeps queued jobs in ordinary Redis lists, which gives the queue no protected status: under memory pressure, the list holding pending jobs can be evicted just like a cache entry, and the jobs it contained are gone before any worker sees them.

Because those jobs are never dispatched or processed, they never reach Laravel's failed-jobs mechanism, and nothing surfaces in application logs. The post adds that memory dashboards will look healthy too — a server sitting inside its memory limit tells you nothing about which keys were sacrificed to keep it there.

cache:clear can empty the queue

The same shared-server arrangement carries a second hazard. Per the post, php artisan cache:clear issues Redis's FLUSHDB command, which wipes every key in the selected database rather than only cache keys. If the cache and the queue are configured to share one Redis database, a routine cache flush takes the queue's contents with it as collateral damage.

A read-only advisor for Redis-backed Laravel apps

Alongside the explanation, the author released a package called Laravel Redis Advisor. It starts from Laravel's own configuration — the cache, queue, session and Horizon settings — to work out which Redis connection backs which subsystem. It then inspects the live server using the INFO command, a sampled SCAN over the keyspace, and a handful of queue length measurements.

The output grades each detected issue by severity, shows the numbers behind it, and proposes a remedy written either as a redis.conf line or as a change to Laravel's configuration. The checks cover:

  • whether queued jobs sit under an eviction policy that may delete them
  • queue backlog size and how long the oldest waiting job has been sitting
  • expired job reservations
  • Horizon's trim settings
  • which queues or session keys a cache:clear run would destroy

The package is strictly read-only: every command it issues passes through a single guard that admits reads and nothing else, so the diagnostic itself cannot mutate or delete data.

Availability

Laravel Redis Advisor installs with composer require amjadiqbal/laravel-redis-advisor. The post states it is MIT licensed, targets Laravel 12 and 13, and has source and documentation on the author's website.

Why it matters

Queues are usually treated as a durability boundary: once a job is pushed, the application assumes it will eventually run. This failure mode breaks that assumption invisibly — jobs are deleted server-side before Laravel ever touches them, so the standard debugging tools of failed-jobs tables, logs and retries stay quiet. The risk is also structural rather than a bug: a policy like allkeys-lru is a reasonable fit for an instance used purely as a cache, but it becomes a liability the moment that same instance also holds queues or sessions. The FLUSHDB behaviour compounds the problem, since an everyday operational command can wipe a queue as a side effect. Automated, read-only auditing of Redis configuration against Laravel's connection map turns this from a post-mortem mystery into a checkable condition — cheap insurance for any application whose jobs carry real consequences, such as payments, notifications or order processing.

  • #laravel
  • #redis
  • #php
  • #queues
  • #devops
  • #open-source

Related posts