← News

Persistent Redis: queues, sessions and Horizon that stay put

News 4 min read

Since 2024 you have had Redis included in every plan, and that hasn't changed. But that Redis is a cache, and it behaves like one: it starts empty every time it restarts and, when it fills up, it discards the keys used least. For the WordPress object cache that is exactly what you want, because everything it stores can be worked out again.

A job queue or a user's session can't be worked out again. If the cache is emptied, a pending job disappears without anyone noticing, and whoever was logged in to your application has to log in again. That is why until now we recommended keeping queues and sessions in the database, and Horizon, which only works with Redis, was left out.

Now, on the Avanza, Max and Elastic plans, you can switch on a persistent Redis.

What makes it different

It is an instance of your own, just for your account. It is Valkey 8, compatible with Redis: the same commands and the same clients, such as PhpRedis. And it behaves the way queues and sessions need:

  • It saves its data to disk every second. It keeps it when it restarts, and in a power cut you lose at most the last second.
  • It deletes nothing when it fills up: it rejects new writes with an error. For a queue that is what you want, the application raising the alarm rather than a job vanishing silently.
  • It is included in the daily backups, like the rest of your files.
  • You choose the memory: 64 MB by default, up to 128 MB on Avanza, 256 MB on Max and 512 MB on Elastic. Queues and sessions take up little: 64 MB is enough for most applications.

If a particular use calls for it, you can change both behaviours: turn off persistence, or let it discard what is used least when it fills up.

Switching it on and connecting

You switch it on in Hosting → your service → Package manager, on the Persistent Redis card. Right there you can see the memory it uses and the space it takes on disk, and you can change its settings, restart it, empty it or switch it off.

It connects through a socket with no password, because only your account's user can open it. In Laravel it takes a few lines in .env, with your cPanel username in place of USUARIO:

REDIS_CLIENT=phpredis
REDIS_HOST=/home/USUARIO/.hostsuar/redis/redis.sock
REDIS_PORT=0

QUEUE_CONNECTION=redis
SESSION_DRIVER=redis

You can use both Redis instances at once: the cache in the usual Redis, and queues and sessions in the persistent one. The guide shows how to separate them in config/database.php.

Horizon, at last

Horizon needs two things: queues in Redis and a process that keeps it running. The first is the persistent Redis; the second, the persistent processes, which arrive at the same time. With both, Horizon runs on your hosting with its dashboard and its metrics.

Bear in mind that the persistent Redis runs as one more process on your account, within its resources, and takes one of the plan's persistent process slots: on Avanza, Redis and Horizon use two of the three.

You'll find the step-by-step, with the connection from Laravel, using it alongside the cache Redis and installing Horizon, in the persistent Redis guide.

We keep improving.

See what we're working on right now or write to us if something's missing.