On one of the systems that I take care of, some times some jobs don’t get dispatched due to a connection problem with Redis and this ends up returning an error to the user, on our side we can ignore this error and just miss this job, I looked for how to deal with it on Google and I didn’t find anything about it.
public function sendMessage(Request $request, Model $model)
{
// Do the necessary stuff
ResolveMessageBilling::dispatch($model, $request->all());
return response()->json([
'message' => 'The message was succesfully sent'
], 200);
}
This is the error we are getting: RedisException - socket error on read socket
How to ignore the error if it occurs? A simple try/catch
can resolve the issue?
public function sendMessage(Request $request, Model $model)
{
// Do the necessary stuff
try {
ResolveMessageBilling::dispatch($model, $request->all());
} catch(Exception $e) {}
return response()->json([
'message' => 'The message was succesfully sent'
], 200);
}
2
Answers
If you want to bypass ANY error, you should use
Throwable
instead ofException
see Error Hierarchy: https://www.php.net/manual/en/language.errors.php7.php
If you want to bypass only the RedisException, you should be able to use:
If you don’t want to setup Redis just want to fixed/remove errors only, follow this article: https://laravel.com/docs/7.x/errors
IF you want to Setup Redis(config -> detabase.php) properly, follow few step like this:
if you needs to Redis sentinal cache, can create new cache connection to use the above sentinal connection like this:
‘stores’ = [
In laravel app, you can easily use via cache facade:
After config Redis properly test again with the clear server cache