My app is dispatching a job, it was working, but there's one job that doesn't get dispatch because there's an error on redis, but this is just one job out of thousands.
RedisClusterException: Error processing response from Redis node!
I'm dispatching the job via this way:
HereTheJob::dispatch($this);
Here's my setup Queue: SQS Cache: redis
I think its using cache here because my job has ShouldBeUnique
, its saving the unique job on cache.
So my question is, when there's an error on redis, how do I retry to dispatch the job?
My app is dispatching a job, it was working, but there's one job that doesn't get dispatch because there's an error on redis, but this is just one job out of thousands.
RedisClusterException: Error processing response from Redis node!
I'm dispatching the job via this way:
HereTheJob::dispatch($this);
Here's my setup Queue: SQS Cache: redis
I think its using cache here because my job has ShouldBeUnique
, its saving the unique job on cache.
So my question is, when there's an error on redis, how do I retry to dispatch the job?
Share asked Mar 11 at 8:04 aceraven777aceraven777 4,5084 gold badges38 silver badges58 bronze badges2 Answers
Reset to default 1✅ How Laravel uses Redis for ShouldBeUnique?
Yes, by default, it uses whatever
cache store
is configured. If it’s Redis, it will hit Redis to check/create that lock before adding the job to the queue.
Laravel Doc Reference
✅ What’s happening in your case:
- When dispatching a ShouldBeUnique job, Laravel tries to acquire a unique lock via Cache::lock().
- If Redis throws a
RedisClusterException
orconnection error
at that point, the dispatch will fail because it can’t check or create the lock. - This won't be retried automatically — it’s happening during dispatch time, not as part of the queued job itself.
✅ How to handle Redis errors during dispatch?
Solution 1:
You can wrap your job dispatch logic within retry()
helper. It will try to dispatch job upto attempt limits. When job will not throw error it won't try further.
retry(3, function () {
HereTheJob::dispatch($this);
}, 1000);
Laravel Doc Reference
Solution 2:
If your Redis cluster has occasional instability and it's only for job uniqueness, consider using database or a single-node Redis instance for unique_job_cache using uniqueVia()
method within your job class:
public function uniqueVia(): Repository
{
return Cache::driver('database');
}
Laravel Doc Reference
I think you need implement fallback mechanism. like this:
create method like this :
// Add fallback storage for unique key
try {
return 'job_' . $this->someUniqueIdentifier;
} catch (\RedisClusterException $e) {
// Use alternative storage like database or file
return $this->getFallbackUniqueId();
}
and use into your function :
try {
return HereTheJob::dispatch($data);
} catch (\RedisClusterException $e) {
// Log the error
\Log::error('Redis Cluster Exception: ' . $e->getMessage());
// Retry with exponential backoff
return HereTheJob::dispatch($data)
->delay(now()->addSeconds(30))
->onQueue('fallback');
}