Top 20 Configuration options in Redis?

Posted by

In Laravel, Redis configuration options are primarily managed through the config/database.php file. Here are the top 20 configuration options for Redis in Laravel, along with example code snippets to illustrate how they can be set:

  1. client: Specifies the Redis client to use (phpredis or predis).
'client' => env('REDIS_CLIENT', 'phpredis'),

2. options.cluster: Configures the Redis cluster mode.

'options' => [
    'cluster' => env('REDIS_CLUSTER', 'redis'),
],

3. options.prefix: Sets a prefix for all keys stored in Redis.

'options' => [
    'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
],

4. default.url: The URL for the default Redis connection.

'default' => [
    'url' => env('REDIS_URL'),
],

5. default.host: The host for the default Redis connection.

'default' => [
    'host' => env('REDIS_HOST', '127.0.0.1'),
],

6. default.username: The username for the default Redis connection.

'default' => [
    'username' => env('REDIS_USERNAME'),
],

7. default.password: The password for the default Redis connection.

'default' => [
    'password' => env('REDIS_PASSWORD'),
],

8. default.port: The port for the default Redis connection.

'default' => [
    'port' => env('REDIS_PORT', '6379'),
],

9. default.database: The database index for the default Redis connection.

'default' => [
    'database' => env('REDIS_DB', '0'),
],

10. cache.database: The database index for the Redis cache connection.

'cache' => [
    'database' => env('REDIS_CACHE_DB', '1'),
],

11. clusters: Configuration for Redis clusters.

12. read_timeout: The read timeout for the Redis connection.

'default' => [
    'read_timeout' => 60,
],

13. context: Additional context options for the Redis connection.

'default' => [
    'context' => [
        // 'auth' => ['username', 'secret'],
        // 'stream' => ['verify_peer' => false],
    ],
],

14. persistent: Whether to use persistent connections.

'default' => [
    'persistent' => false,
],

15. persistent_id: The identifier for persistent connections.

'default' => [
    'persistent_id' => null,
],

16. retry_interval: The interval between reconnection attempts.

'default' => [
    'retry_interval' => 100,
],

17. timeout: The timeout for the Redis connection.

'default' => [
    'timeout' => 10,
],

18. name: The name of the Redis connection.

'default' => [
    'name' => 'default',
],

19. stream: Stream context options for the Redis connection.

'default' => [
    'stream' => [
        'verify_peer' => false,
    ],
],

20. auth: Authentication credentials for the Redis connection.

'default' => [
    'auth' => ['username', 'secret'],
],

The redis array in the config/database.php file contains these configurations. You can adjust these settings based on the needs of your application and the particular Redis configuration you’re using. Don’t forget to change your.env file to reflect the correct Redis server values.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x