You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: redis.md
+59-45
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ Before using Redis with Laravel, we encourage you to install and use the [PhpRed
20
20
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:
21
21
22
22
```shell
23
-
composer require predis/predis
23
+
composer require predis/predis:^2.0
24
24
```
25
25
26
26
<aname="configuration"></a>
@@ -32,18 +32,27 @@ You may configure your application's Redis settings via the `config/database.php
@@ -69,18 +83,14 @@ Each Redis server defined in your configuration file is required to have a name,
69
83
70
84
By default, Redis clients will use the `tcp` scheme when connecting to your Redis servers; however, you may use TLS / SSL encryption by specifying a `scheme` configuration option in your Redis server's configuration array:
71
85
72
-
'redis' => [
73
-
74
-
'client' => env('REDIS_CLIENT', 'phpredis'),
75
-
76
-
'default' => [
77
-
'scheme' => 'tls',
78
-
'host' => env('REDIS_HOST', '127.0.0.1'),
79
-
'password' => env('REDIS_PASSWORD'),
80
-
'port' => env('REDIS_PORT', 6379),
81
-
'database' => env('REDIS_DB', 0),
82
-
],
83
-
86
+
'default' => [
87
+
'scheme' => 'tls',
88
+
'url' => env('REDIS_URL'),
89
+
'host' => env('REDIS_HOST', '127.0.0.1'),
90
+
'username' => env('REDIS_USERNAME'),
91
+
'password' => env('REDIS_PASSWORD'),
92
+
'port' => env('REDIS_PORT', '6379'),
93
+
'database' => env('REDIS_DB', '0'),
84
94
],
85
95
86
96
<aname="clusters"></a>
@@ -92,35 +102,42 @@ If your application is utilizing a cluster of Redis servers, you should define t
By default, clusters will perform client-side sharding across your nodes, allowing you to pool nodes and create a large amount of available RAM. However, client-side sharding does not handle failover; therefore, it is primarily suited for transient cached data that is available from another primary data store.
126
+
By default, Laravel will use native Redis clustering since the `options.cluster` configuration value is set to `redis`. Redis clustering is a great default option, as it gracefully handles failover.
127
+
128
+
Laravel also supports client-side sharding. However, client-side sharding does not handle failover; therefore, it is primarily suited for transient cached data that is available from another primary data store.
109
129
110
-
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:
130
+
If you would like to use client-side sharding instead of native Redis clustering, you may remove the `options.cluster` configuration value within your application's `config/database.php` configuration file:
111
131
112
132
'redis' => [
113
133
114
134
'client' => env('REDIS_CLIENT', 'phpredis'),
115
135
116
-
'options' => [
117
-
'cluster' => env('REDIS_CLUSTER', 'redis'),
118
-
],
119
-
120
136
'clusters' => [
121
137
// ...
122
138
],
123
139
140
+
// ...
124
141
],
125
142
126
143
<aname="predis"></a>
@@ -135,25 +152,18 @@ If you would like your application to interact with Redis via the Predis package
135
152
// ...
136
153
],
137
154
138
-
In addition to the default `host`, `port`, `database`, and `password` server configuration options, Predis supports additional [connection parameters](https://github.com/nrk/predis/wiki/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:
155
+
In addition to the default configuration options, Predis supports additional [connection parameters](https://github.com/nrk/predis/wiki/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:
139
156
140
157
'default' => [
141
-
'host' => env('REDIS_HOST', 'localhost'),
158
+
'url' => env('REDIS_URL'),
159
+
'host' => env('REDIS_HOST', '127.0.0.1'),
160
+
'username' => env('REDIS_USERNAME'),
142
161
'password' => env('REDIS_PASSWORD'),
143
-
'port' => env('REDIS_PORT', 6379),
144
-
'database' => 0,
162
+
'port' => env('REDIS_PORT', '6379'),
163
+
'database' => env('REDIS_DB', '0'),
145
164
'read_write_timeout' => 60,
146
165
],
147
166
148
-
<aname="the-redis-facade-alias"></a>
149
-
#### The Redis Facade Alias
150
-
151
-
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:
@@ -163,16 +173,18 @@ By default, Laravel will use the PhpRedis extension to communicate with Redis. T
163
173
164
174
'client' => env('REDIS_CLIENT', 'phpredis'),
165
175
166
-
// Rest of Redis configuration...
176
+
// ...
167
177
],
168
178
169
-
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:
179
+
In addition to the default 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:
170
180
171
181
'default' => [
172
-
'host' => env('REDIS_HOST', 'localhost'),
182
+
'url' => env('REDIS_URL'),
183
+
'host' => env('REDIS_HOST', '127.0.0.1'),
184
+
'username' => env('REDIS_USERNAME'),
173
185
'password' => env('REDIS_PASSWORD'),
174
-
'port' => env('REDIS_PORT', 6379),
175
-
'database' => 0,
186
+
'port' => env('REDIS_PORT', '6379'),
187
+
'database' => env('REDIS_DB', '0'),
176
188
'read_timeout' => 60,
177
189
'context' => [
178
190
// 'auth' => ['username', 'secret'],
@@ -190,11 +202,13 @@ The PhpRedis extension may also be configured to use a variety of serializers an
0 commit comments