Multiple Ways to Delete Laravel Redis Keys
Hello Artisan, in this tutorial i will show you how to delete redis key from using redis cli or using Laravel artisan command or using Laravel facades. Hope you will enjoy this tutorial. Hope you already know that Redis is an in-memory data structure store, used as a distributed, in-memory key–value database, cache and message broker, with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes.
Now we will see how we can set and get our redis key from redis cli and how we can remove redis queue job from Laravel application. Let's see.
Using Laravel Command
This is the first way to clear a Redis queue is to use the artisan queue clear:command and this is the easiest you can do. Just open up the terminal and type the command below.
php artisan queue:clear [connection] [queue]
Using Redis Cli
We can do the same thing using redis-cli. You know that redis has also its command line interface to run redis command. When you are in Redis CLI, just run the command below like
Thirdly, we can do the same staff to use Laravel facade then you can create a route closure or console command to run the Redis command.
use Redis; Redis::command('flushdb');
If you want to do it using tinker then run below command
php artisan tinker //then \\Redis::command(‘flushdb’);
Do you know that we can set and get redis key using redis-cli. How we can do that? In this section we will set redis key and then we will fetch redis key with its value and then we will remove all of our redis keys.
Hope you have enjoyed this tutorial.