Redis and Laravel queues. Using Lrange

Sami Samiuddin
1 min readFeb 8, 2025

--

Looks like I spent ages trying to figure this one out!

I’m using Redis as queue driver to process some jobs.. there’s edge case where I need to remove an old job from Redis so it doesn’t get picked by worker..

Anyways, the queue I need to inspect is: laravel_queues:default

>> keys *

1) “laravel_queues:default:notify”
2) “laravel_database_queues:default:notify”
3) “laravel_database_queues:default”
4) “laravel_queues:default”

Now I could easily see the data within the list using:
>> lrange laravel_database_queues:default 0 -1

Data:
1) “{\”uuid\”:\”43a0ef64-e590–4dd8-b5ed-e055b72e5a95\”,\”displayName\”:\”App\\\\Jobs\\\\DownloadXmlJob\”,\”job\”:\”Illuminate\\\\Queue\\\\CallQueuedHandler@call\”,\”maxTries\”:3,\”maxExceptions\”:null,\”failOnTimeout\”:false,\”backoff\”:null,\”timeout\”:null,\”retryUntil\”:null,\”data\”:{\”commandName\”:\”App\\\\Jobs\\\\DownloadXmlJob\”,\”command\”:\”O:23:\….

Easy right!?

Now lets try getting the same thing within the Laravel application (which uses Phpredis library behind the scene):

>> Redis::lrange(‘laravel_database_queues:default’, 0, -1);

Data:
[] // empty array!

I couldn’t figure out why!
Turns out Laravel prefixes the queues, in my case it prefixed the queue with laravel_database_

What I didn’t know if that you must drop the prefix when retrieving the items from the queue list!

So I had to use use the name without any prefixes:
>> Redis::lrange(‘queues:default’, 0, -1);

Interesting that this isn’t mentioned anywhere in the docs! it magically adds the queue prefix to whatever KEY we want to retrieve in lrange!

Anyways, hope this helps someone who’s having to use queues!

FREE 50+ page PDF → Become an unstoppable programmer in 15 minutes →
https://samiwritescode.gumroad.com/l/crazy-software-developer-handbook

Contact me with your questions!
phpdevsami@gmail.com

Blog:
https://supremecodr.com

--

--

Sami Samiuddin
Sami Samiuddin

No responses yet