@@ -54,7 +54,7 @@ We've included this amazing video by TechWorld with Nana to help you get started
5454 </div>
5555</section >
5656
57- To get started with Leaf Redis, you need to have Redis installed on your machine. You can install Redis PHP extension by following the instructions [ here] ( https://github.com/phpredis/phpredis/blob/develop/INSTALL.md ) .
57+ To get started with Leaf Redis, you need to have Redis installed on your machine. You can install Redis PHP extension by following the instructions [ here] ( https://github.com/phpredis/phpredis/blob/develop/INSTALL.md ) , however, if you can't install the extension, you can use the [ Predis ] ( https://github.com/predis/predis ) composer package. Leaf Redis supports both the Redis PHP extension and Predis, and will automatically detect which one you have installed and work with it .
5858
5959After that, we can install Leaf Redis through composer or the leaf cli.
6060
@@ -101,6 +101,18 @@ redis()->set([
101101]);
102102```
103103
104+ You can also set values with an expiration time by passing in a third argument.
105+
106+ ``` php:no-line-numbers
107+ redis()->set('name', 'Michael', 3600);
108+ ```
109+
110+ If you need Leaf to ignore the expiration time, you can pass in ` 0 ` as the third argument.
111+
112+ ``` php:no-line-numbers
113+ redis()->set('name', 'Michael', 0);
114+ ```
115+
104116## Getting values
105117
106118You can get values from Redis using the ` get() ` method. The ` get() ` method takes in a key and returns the value.
@@ -117,6 +129,44 @@ $values = redis()->get(['name', 'age']);
117129// $values => ['name' => 'Michael', 'age' => 22]
118130```
119131
132+ ## Deleting values
133+
134+ You can delete values from Redis using the ` delete() ` method. The ` delete() ` method takes in a key and deletes the value.
135+
136+ ``` php:no-line-numbers
137+ redis()->delete('name');
138+ ```
139+
140+ You can also delete multiple values at once by passing in an array.
141+
142+ ``` php:no-line-numbers
143+ redis()->delete(['name', 'age']);
144+ ```
145+
146+ ## Checking if a key exists
147+
148+ You can check if a key exists in Redis using the ` exists() ` method. The ` exists() ` method takes in a key and returns a boolean.
149+
150+ ``` php:no-line-numbers
151+ $exists = redis()->exists('name');
152+ ```
153+
154+ ## Getting all keys
155+
156+ You can get all keys in Redis using the ` keys() ` method.
157+
158+ ``` php:no-line-numbers
159+ $keys = redis()->keys();
160+ ```
161+
162+ ## Flushing Redis
163+
164+ You can flush all keys in Redis using the ` flush() ` method.
165+
166+ ``` php:no-line-numbers
167+ redis()->flush();
168+ ```
169+
120170## Configuring Leaf Redis
121171
122172Most of the Leaf Redis config can be done using your ` .env ` file. Here are the available configurations:
@@ -137,106 +187,110 @@ php leaf config:publish redis
137187This will generate a ` config/redis.php ` file in your project root. You can then set your configurations in this file.
138188
139189``` php
140- /*
141- |------------------------------------------------------------
142- | Redis host
143- |------------------------------------------------------------
144- |
145- | Set the host for redis connection
146- |
147- */
148- 'host' => '127.0.0.1',
149-
150- /*
151- |------------------------------------------------------------
152- | Redis host port
153- |------------------------------------------------------------
154- |
155- | Set the port for redis host
156- |
157- */
158- 'port' => 6379,
159-
160- /*
161- |------------------------------------------------------------
162- | Redis auth
163- |------------------------------------------------------------
164- |
165- | Set the password for redis connection
166- |
167- */
168- 'password' => null,
169-
170- /*
171- |------------------------------------------------------------
172- | Redis session handler
173- |------------------------------------------------------------
174- |
175- | Set redis as session save handler
176- |
177- */
178- 'session' => false,
179-
180- /*
181- |------------------------------------------------------------
182- | Redis connection timeout
183- |------------------------------------------------------------
184- |
185- | Value in seconds (optional, default is 0.0 meaning unlimited)
186- |
187- */
188- 'connection.timeout' => 0.0,
189-
190- /*
191- |------------------------------------------------------------
192- | Redis connection reserved
193- |------------------------------------------------------------
194- |
195- | should be null if $retryInterval is specified
196- |
197- */
198- 'connection.reserved' => null,
199-
200- /*
201- |------------------------------------------------------------
202- | Redis session handler
203- |------------------------------------------------------------
204- |
205- | Connection retry interval in milliseconds.
206- |
207- */
208- 'connection.retryInterval' => 0,
209-
210- /*
211- |------------------------------------------------------------
212- | Redis connection read timeout
213- |------------------------------------------------------------
214- |
215- | Value in seconds (optional, default is 0 meaning unlimited
216- |
217- */
218- 'connection.readTimeout' => 0.0,
219-
220- /*
221- |------------------------------------------------------------
222- | Redis session save_path
223- |------------------------------------------------------------
224- |
225- | Save path for redis session. Leave null to automatically
226- | generate the session save path. You can also use
227- | multiple save urls by passing in an array.
228- |
229- */
230- 'session.savePath' => null,
231-
232- /*
233- |------------------------------------------------------------
234- | Redis session save_path options
235- |------------------------------------------------------------
236- |
237- | Options for session save path. You can pass in multiple
238- | options in the order of the save path above.
239- |
240- */
241- 'session.saveOptions' => [],
190+ <?php
191+
192+ return [
193+ /*
194+ |-----------------------------------------------------------------
195+ | Redis host
196+ |-----------------------------------------------------------------
197+ |
198+ | Set the host for redis connection
199+ |
200+ */
201+ 'host' => _env('REDIS_HOST', '127.0.0.1'),
202+
203+ /*
204+ |-----------------------------------------------------------------
205+ | Redis host port
206+ |-----------------------------------------------------------------
207+ |
208+ | Set the port for redis host
209+ |
210+ */
211+ 'port' => _env('REDIS_PORT', 6379),
212+
213+ /*
214+ |-----------------------------------------------------------------
215+ | Redis auth
216+ |-----------------------------------------------------------------
217+ |
218+ | Set the password for redis connection
219+ |
220+ */
221+ 'password' => _env('REDIS_PASSWORD', null),
222+
223+ /*
224+ |-----------------------------------------------------------------
225+ | Redis session handler
226+ |-----------------------------------------------------------------
227+ |
228+ | Set redis as session save handler
229+ |
230+ */
231+ 'session' => _env('REDIS_SESSION', false),
232+
233+ /*
234+ |-----------------------------------------------------------------
235+ | Redis connection timeout
236+ |-----------------------------------------------------------------
237+ |
238+ | Value in seconds (optional, default is 0.0 meaning unlimited)
239+ |
240+ */
241+ 'connection.timeout' => 0.0,
242+
243+ /*
244+ |-----------------------------------------------------------------
245+ | Redis connection reserved
246+ |-----------------------------------------------------------------
247+ |
248+ | should be null if $retryInterval is specified
249+ |
250+ */
251+ 'connection.reserved' => null,
252+
253+ /*
254+ |-----------------------------------------------------------------
255+ | Redis session handler
256+ |-----------------------------------------------------------------
257+ |
258+ | Connection retry interval in milliseconds.
259+ |
260+ */
261+ 'connection.retryInterval' => 0,
262+
263+ /*
264+ |-----------------------------------------------------------------
265+ | Redis connection read timeout
266+ |-----------------------------------------------------------------
267+ |
268+ | Value in seconds (optional, default is 0 meaning unlimited
269+ |
270+ */
271+ 'connection.readTimeout' => 0.0,
272+
273+ /*
274+ |-----------------------------------------------------------------
275+ | Redis session save_path
276+ |-----------------------------------------------------------------
277+ |
278+ | Save path for redis session. Leave null to automatically
279+ | generate the session save path. You can also use
280+ | multiple save urls by passing in an array.
281+ |
282+ */
283+ 'session.savePath' => null,
284+
285+ /*
286+ |-----------------------------------------------------------------
287+ | Redis session save_path options
288+ |-----------------------------------------------------------------
289+ |
290+ | Options for session save path. You can pass in multiple
291+ | options in the order of the save path above.
292+ |
293+ */
294+ 'session.saveOptions' => [],
295+ ];
242296```
0 commit comments