Set up Redis
Back to home
On this page
With Laravel, you can use Redis to handle session storage, cache storage, and queues.
1. Add the Redis service
-
Add the service to your app configuration using the
services
top-level key:.upsun/config.yamlservices: [...] redis: type: redis:7.0
-
To connect the service to your app, add the following relationship:
.upsun/config.yamlapplications: myapp: [...] relationships: redis: services: [...] redis: type: redis:7.0
2. Configure your Redis service
The Redis configuration is exposed via the following environment variables
(where REDIS
is the upper-cased version of the key defined in the relationship):
REDIS_URL
: The Redis URLREDIS_HOST
: The Redis hostREDIS_PORT
: The Redis portREDIS_SCHEME
: The Redis scheme
If the relationship is named redis
, Laravel automatically detects these variables and configure its own Redis driver the right way.
If not, you can map the variables in the .environment
file.
You can specify the Redis client in your .environment
file:
export REDIS_CLIENT="phpredis"
Note
If using phpredis
, make sure you add redis
in the list of PHP runtime
extensions in your .upsun/config.yaml
:
applications:
myapp:
[...]
runtime:
extensions:
- redis
3. Store the Laravel cache in Redis
To enable cache storage in Redis, add the following environment variable to your .environment
file:
export CACHE_STORE="redis"
4. Store Laravel sessions in Redis
Laravel relies on the SESSION_DRIVER
variable to store sessions. Therefore, add the following environment variable to your .environment
file:
export SESSION_DRIVER="redis"
5. Use Redis for Laravel queues
For a basic queueing system, configure the QUEUE_CONNECTION
in your .environment
file as follows:
export QUEUE_CONNECTION="redis"
For more information, see the Laravel Queues documentation and Upsun’s Horizon configuration page.