Skip to content

Commit e7de3bb

Browse files
committed
inital code
1 parent 3120ea2 commit e7de3bb

File tree

5 files changed

+135
-1
lines changed

5 files changed

+135
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
.DS_Store

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
1-
# laravel-redis-queue
1+
# Laravel Redis Queue
2+
3+
A little command line tool for clearing Laravel redis queues.
4+
5+
## Basic Clear
6+
7+
This command clears the redis queue defined in your `config/queue.php` file. The configuration is normally set to `default`.
28

39
```shell
410
php artisan queue:redis -C
11+
```
12+
13+
Outputs,
14+
15+
```
16+
Clearing Redis queues:default
17+
```
18+
19+
## Defined Queue Clear
20+
21+
To clear a defined queue specify it in the artisan command as an augument.
22+
23+
```shell
24+
php artisan queue:redis emails -C
525
```

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "kevindees/laravel-redis-queue",
3+
"description": "Redis queue managment for laravel.",
4+
"keywords": ["laravel", "queue", "redis"],
5+
"license": "MIT",
6+
"require": {
7+
"php": "^7.0",
8+
"predis/predis": "^1.1"
9+
},
10+
"autoload": {
11+
"psr-4": {
12+
"QueueRedis\\": "src/"
13+
}
14+
},
15+
"extra": {
16+
"laravel": {
17+
"providers": [
18+
"QueueRedis\\QueueRedisServiceProvider"
19+
]
20+
}
21+
}
22+
}

src/QueueRedisCommand.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
<?php
3+
namespace QueueRedis;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Redis;
7+
8+
class QueueRedisCommand extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'queue:redis
16+
{queue? : The queue you wish to target}
17+
{--C|clear : Clear the queue}';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Flush redis queue';
25+
26+
protected $queue;
27+
protected $clear;
28+
29+
/**
30+
* Create a new command instance.
31+
*
32+
* @return void
33+
*/
34+
public function __construct()
35+
{
36+
parent::__construct();
37+
}
38+
39+
/**
40+
* Execute the console command.
41+
*
42+
* @return mixed
43+
*/
44+
public function handle()
45+
{
46+
$this->queue = $this->argument('queue') ?: config('queue.connections.redis.queue');
47+
$this->clear = $this->option('clear');
48+
49+
if($this->clear) {
50+
$this->clear();
51+
}
52+
}
53+
54+
protected function clear() {
55+
$del = 'queues:' . escapeshellcmd($this->queue);
56+
$this->info('Clearing Redis ' . $del);
57+
Redis::connection()->del($del);
58+
}
59+
}

src/QueueRedisServiceProvider.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace QueueRedis;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class QueueRedisServiceProvider extends ServiceProvider {
8+
9+
/**
10+
* Register bindings in the container.
11+
*
12+
* @return void
13+
*/
14+
public function register()
15+
{
16+
}
17+
18+
/**
19+
* Bootstrap the application services.
20+
*
21+
* @return void
22+
*/
23+
public function boot()
24+
{
25+
if ($this->app->runningInConsole()) {
26+
$this->commands([
27+
QueueRedisCommand::class,
28+
]);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)