> ## Documentation Index
> Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up Redis

> Setting up Redis for cache, sessions & queues


With Laravel, you can use Redis to handle session storage, cache storage, and queues.

## 1. Add the Redis service

1. [Add the service](/docs/add-services#add-a-service) to your app configuration using the `services` top-level key:

   ```yaml .upsun/config.yaml theme={null}
   services:
     [...]
     redis:
       type: redis:7.0
   ```

2. To connect the service to your app, add the following relationship:

   ```yaml .upsun/config.yaml theme={null}
   applications:
     myapp:
       [...]
       relationships:
         redis:

   services:
     [...]
     redis:
       type: redis:7.0
   ```

## 2. Configure your Redis service

The [Redis](/docs/add-services/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 URL
* `REDIS_HOST`: The Redis host
* `REDIS_PORT`: The Redis port
* `REDIS_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:

```bash .environment theme={null}
export REDIS_CLIENT="phpredis"
```

<Warning>
  If using `phpredis`, make sure you add `redis` in the list of PHP `runtime` extensions in your `.upsun/config.yaml`:

  ```yaml .upsun/config.yaml theme={null}
  applications:
    myapp:
      [...]
      runtime:
        extensions:
          - redis
  ```
</Warning>

## 3. Store the Laravel cache in Redis

To enable cache storage in Redis, add the following environment variable to your `.environment` file:

```bash .environment theme={null}
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:

```bash .environment theme={null}
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:

```bash .environment theme={null}
export QUEUE_CONNECTION="redis"
```

For more information, see the [Laravel Queues documentation](https://laravel.com/docs/master/queues)
and Upsun's [Horizon configuration page](/docs/get-started/stacks/laravel/laravel-horizon).
