Skip to content
Docs

Valkey for cache, sessions and queues

Add Valkey, the open copy of Redis, as a cache or for queues and sessions. Laravel's cache, queue and session settings are added for you.

Updated 17 Oct 20263 min read

Valkey is an in-memory store for caches, sessions and queues. It's the free, open copy of Redis, so anything that talks to Redis talks to Valkey: Laravel, BullMQ, Sidekiq, Celery and the Redis libraries of every language. You add it as a Cache, and choose what it's for when you make it.

Cache, or queues and sessions

This choice matters, because the two need opposite things.

A cacheQueues and sessions
When it's fullThe least used keys goNo key is ever dropped
On diskNothing is keptEvery write is saved
WarningNone neededYou're told at 80% of its memory
Laravel settings addedCACHE_STORE and CACHE_DRIVERQUEUE_CONNECTION and SESSION_DRIVER

A cache that drops old keys is doing its job. A queue that drops a key has lost a job, and a session store that drops one has logged a customer out. That's why a Valkey for queues never drops anything, and warns you before it fills.

The choice is made once, when you add it. If one app needs a cache and a queue, the simplest way is one Valkey for queues and sessions, with the variable CACHE_STORE=redis added by you in the project's Variables tab. Its keys are never dropped, so give it enough memory, and set a lifetime on what you cache.

Add one

  1. Open your project's Overview, and under Add a service choose Cache.

  2. Under What it's for, choose A cache or Queues and sessions.

  3. Set its memory and processor limits with the sliders. The lowest memory Valkey may have is 64 MB.

  4. Keep the name cache or change it, tick the apps that should get its details, and choose Add.

It pays for the memory and processor it really uses, every hour, like an own database.

Example: Asha's queue

Asha's Laravel shop sends order emails from a queue worker. She adds a Valkey named queue for Queues and sessions, and ticks her app web. Web gets:

Terminal
REDIS_HOST=queue.duka.internal
REDIS_PORT=6379
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis

REDIS_PASSWORD and REDIS_URL are added too. Web redeploys with them, and so does its worker, which runs php artisan queue:work. Orders now queue in Valkey, and her customers stay logged in across deployments.

A Valkey made as A cache sets CACHE_STORE=redis and CACHE_DRIVER=redis instead. Both kinds use the same four REDIS_ names, so if one app gets the details of two Valkeys, the one attached first fills those names. Detach it, and the other one's values take their place.

Connecting from code

Your app reaches Valkey with its host, port and password. Most libraries take REDIS_URL alone:

js
import { Queue } from "bullmq";
const queue = new Queue("emails", { connection: { url: process.env.REDIS_URL } });

The address's user is default. Valkey has no extra users, no tables and no import or export: it holds what your app puts in it.

Memory

When a cache is full, it makes room by itself. For queues and sessions, watch the warning at 80%: raise its memory limit with Change limits before it fills. A Valkey for queues saves to disk, so a restart keeps its jobs.

New passwords

Valkey has a single password. When you choose Change the password, Valkey restarts with the new one, and the attached apps restart with it too. For those seconds, a new connection with the old password is refused.