Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andysbhai's avatar

What happens to Jobs in a Redis Queue when the server restarts?

I have an application that's scheduling some Jobs relatively far into the future (anywhere between 1-7 days). In testing so far I've used the database queue driver, which gives me some nice error tolerance: when the server shuts down, the jobs will still exist in the database, and therefore I don't run the risk of losing jobs during deployments, maintenance, etc.

Due to deadlock concerns + performance (and I'd like to use Horizon), in production I want to use Redis as a queue driver. I'm wondering what happens to the Jobs that are still in the queue when the server is shutdown, whether there's a mechanic that then stores the jobs in the database and reads them into memory again when the server is started.

Any pointers on the behavior of queues and shutdowns is welcome, TIA.

0 likes
1 reply
AddWebContribution's avatar

@andysbhai When the Redis server is shut down, all jobs in the Redis queue will be lost. Redis is an in-memory data structure store, and it doesn't persist data to disk by default. Therefore, when the Redis server is stopped, all data in memory is lost, including your queued jobs.

To avoid losing queued jobs when the Redis server is shut down, you can use Redis persistence features, such as RDB (Redis Database) or AOF (Append-Only File) to persist data to disk. RDB is a point-in-time snapshot of the Redis database, while AOF logs all write operations performed on the database.

You can configure Redis to automatically save data to disk periodically, or manually trigger a save command. When Redis restarts, it will reload the data from the persistence file, including your queued jobs.

Another option is to use a hybrid approach where you store the jobs in both Redis and a persistent database such as MySQL or PostgreSQL. This way, if Redis crashes, you can still retrieve the jobs from the persistent database.

In summary, if you want to use Redis as a queue driver, you need to consider the persistence strategy to ensure that you don't lose queued jobs when the Redis server is shut down. Redis persistence features can help to ensure data durability, or you can use a hybrid approach to store the jobs in both Redis and a persistent database.

2 likes

Please or to participate in this conversation.