Skip to content

Commit

Permalink
inital code
Browse files Browse the repository at this point in the history
  • Loading branch information
kevindees committed Aug 8, 2018
1 parent 3120ea2 commit e7de3bb
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
.DS_Store
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# laravel-redis-queue
# Laravel Redis Queue

A little command line tool for clearing Laravel redis queues.

## Basic Clear

This command clears the redis queue defined in your `config/queue.php` file. The configuration is normally set to `default`.

```shell
php artisan queue:redis -C
```

Outputs,

```
Clearing Redis queues:default
```

## Defined Queue Clear

To clear a defined queue specify it in the artisan command as an augument.

```shell
php artisan queue:redis emails -C
```
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "kevindees/laravel-redis-queue",
"description": "Redis queue managment for laravel.",
"keywords": ["laravel", "queue", "redis"],
"license": "MIT",
"require": {
"php": "^7.0",
"predis/predis": "^1.1"
},
"autoload": {
"psr-4": {
"QueueRedis\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"QueueRedis\\QueueRedisServiceProvider"
]
}
}
}
59 changes: 59 additions & 0 deletions src/QueueRedisCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

<?php
namespace QueueRedis;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class QueueRedisCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'queue:redis
{queue? : The queue you wish to target}
{--C|clear : Clear the queue}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Flush redis queue';

protected $queue;
protected $clear;

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->queue = $this->argument('queue') ?: config('queue.connections.redis.queue');
$this->clear = $this->option('clear');

if($this->clear) {
$this->clear();
}
}

protected function clear() {
$del = 'queues:' . escapeshellcmd($this->queue);
$this->info('Clearing Redis ' . $del);
Redis::connection()->del($del);
}
}
31 changes: 31 additions & 0 deletions src/QueueRedisServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace QueueRedis;

use Illuminate\Support\ServiceProvider;

class QueueRedisServiceProvider extends ServiceProvider {

/**
* Register bindings in the container.
*
* @return void
*/
public function register()
{
}

/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
if ($this->app->runningInConsole()) {
$this->commands([
QueueRedisCommand::class,
]);
}
}
}

0 comments on commit e7de3bb

Please sign in to comment.