Skip to main content
Redis is a fast in-memory key-value store used by many Laravel features as a backend. This page covers everything from configuration to commands and Pub/Sub.

Cache

Use Redis as a cache driver

Queues

Use Redis as a queue driver

Broadcasting

Real-time messaging with Pub/Sub

Introduction

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, and sorted sets. Laravel uses Redis across multiple features:

Choosing a client

Laravel supports two Redis clients: PhpRedis (a PHP extension) and Predis (a PHP package).
Laravel 13 defaults to PhpRedis. PhpRedis is recommended for production. If you use Laravel Sail, PhpRedis is already installed in your Docker container.

Configuration

config/database.php

Redis settings live in the redis array in config/database.php:

Environment variables

Set the connection details in your .env file:
You can also use a URL format:

TLS / SSL connections

To use TLS encryption, add the scheme option to a connection:

Clusters

Define a Redis cluster using the clusters key in config/database.php:
By default, options.cluster is set to redis, enabling native Redis clustering with automatic failover. To use client-side sharding with Predis instead, remove the options.cluster key. Note that client-side sharding does not handle failover and is best suited for transient cached data.

Predis

Install the package and set the environment variable:
Predis supports additional connection parameters:

Retry and backoff (Predis)

Predis 3.4.0 and later supports built-in retry and backoff configuration. Configure retries using the max_retries option and configure the backoff strategy using the retry option. The retry option should be an array keyed by one of the following strategy classes: NoBackoff, EqualBackoff, or ExponentialBackoff:
When using Predis with a Redis cluster, you may define retry configuration in the parameters option of your cluster configuration:

PhpRedis

PhpRedis is installed via PECL (pre-installed in Laravel Sail). It supports these additional options: name, persistent, persistent_id, prefix, read_timeout, retry_interval, max_retries, backoff_algorithm, backoff_base, backoff_cap, timeout, and context.

Retry and backoff (PhpRedis)

Configure reconnection behavior with these options. Supported backoff algorithms: default, decorrelated_jitter, equal_jitter, exponential, uniform, constant.

Unix socket connections

Use a Unix socket instead of TCP to eliminate TCP overhead when Redis runs on the same server:

Serialization and compression

Configure a serializer and compression algorithm in the options array:
Available serializers: Redis::SERIALIZER_NONE (default), Redis::SERIALIZER_PHP, Redis::SERIALIZER_JSON, Redis::SERIALIZER_IGBINARY, Redis::SERIALIZER_MSGPACK. Available compression algorithms: Redis::COMPRESSION_NONE (default), Redis::COMPRESSION_LZF, Redis::COMPRESSION_ZSTD, Redis::COMPRESSION_LZ4.

Interacting with Redis

The Redis facade

The Redis facade supports dynamic methods — you can call any Redis command directly on it:
Pass arguments just as you would to the Redis command:
Use the command method to pass the command name and arguments explicitly:

Multiple connections

Switch between named connections defined in config/database.php:

Transactions

transaction() wraps Redis’s MULTI/EXEC commands. All commands in the closure run as a single atomic operation:
You cannot read values from Redis inside a transaction — the entire closure is queued and executed as one atomic block by EXEC.

Lua scripts

The eval method executes a Lua script atomically and can read Redis values during execution:
Arguments: Lua script → number of keys → key names → additional arguments. Keys are accessed as KEYS[1], KEYS[2], etc., and extra arguments as ARGV[1], etc.

Pipelining

Send many commands at once to reduce network round trips. Commands are executed in order but not atomically:
Pipelining is not atomic. For atomic multi-command operations, use transaction() or a Lua script instead.

Pub / Sub

Laravel provides a convenient interface to Redis’s publish and subscribe commands.

Subscribing

Because subscribe starts a long-running process, call it from an Artisan command:

Publishing

Publish messages from any part of your application:

Wildcard subscriptions

Use psubscribe to subscribe to channels matching a pattern. The channel name is passed as the second argument:

Quick reference

  • Production: PhpRedis (PECL extension, best performance)
  • Development / restricted environments: Predis (composer require predis/predis)
  • Laravel Sail: PhpRedis is pre-installed
Last modified on July 3, 2026