Before using Redis with Laravel, we encourage you to install and use the phpredis PHP extension via PECL. The extension is more complex to install compared to "user-land" PHP packages but may yield better performance for applications that make heavy use of Redis. If you are using Laravel Sail, this extension is already installed in your application's Docker container.
If you are unable to install the phpredis extension, you may install the predis/predis package via Composer. Predis is a Redis client written entirely in PHP and does not require any additional extensions:
You may configure your application's Redis settings via the config/database.php configuration file. Within this file, you will see a redis array containing the Redis servers utilized by your application:
If you would like to use native Redis clustering instead of client-side sharding, you may specify this by setting the options.cluster configuration value to redis within your application's config/database.php configuration file:
In addition to the default host, port, database, and password server configuration options, Predis supports additional connection parameters that may be defined for each of your Redis servers. To utilize these additional configuration options, add them to your Redis server configuration in your application's config/database.php configuration file:
Laravel's config/app.php configuration file contains an aliases array which defines all of the class aliases that will be registered by the framework. By default, no Redis alias is included because it would conflict with the Redis class name provided by the phpredis extension. If you are using the Predis client and would like to add a Redis alias, you may add it to the aliases array in your application's config/app.php configuration file:
By default, Laravel will use the phpredis extension to communicate with Redis. The client that Laravel will use to communicate with Redis is dictated by the value of the redis.client configuration option, which typically reflects the value of the REDIS_CLIENT environment variable:
In addition to the default scheme, host, port, database, and password server configuration options, phpredis supports the following additional connection parameters: name, persistent, persistent_id, prefix, read_timeout, retry_interval, timeout, and context. You may add any of these options to your Redis server configuration in the config/database.php configuration file:
You should see messages go by as the sentinels discover one another and ensure all the nodes are properly configured. You can check the replication status with salticid redis.replication. salticid redis.stop will shut down the Redis servers and sentinels alike.
You can run redis-cli locally on your machine. You will need to install redis-cli onto your machine. A copy and pastable redis-cli command is available in the External Access section of your Redis settings. You will need to enable Allow connections from outside of your private network and configure Access Control of your Redis instance.
df19127ead