PHP code example of lpks / redis-queue

1. Go to this page and download the library: Download lpks/redis-queue library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lpks / redis-queue example snippets




edisQueue\Client;
use RedisQueue\Message;
use RedisQueue\Worker;

class WorkerSample extends Worker
{
    public function do(Message $message)
    {
        if ($message->cmd === 'write') {
            $content = $message->text;
            echo "$content\n";
        }
    }
}

$client = new Client();
$client->enableGracefulShutdown(); // Allow Ctrl+C / kill

try {
    $client->loop('test_queue', new WorkerSample());
} catch (Exception $e) {
    echo '[Server] Fatal error: ' . $e->getMessage() . "\n";
    exit(1);
}



edisQueue\Client;

try {
    $client = new Client();

    $data = [
        'cmd' => 'write',
        'text' => 'Hello world!',
    ];

    $client->push('test_queue', $data);

    echo "RPUSH " . json_encode($data) . " .\n";
} catch (Exception $e) {
    echo $e->getMessage();
}

$client = new Client(string $host = '127.0.0.1', int $port = 6379, array $options = []);

$client = new Client('127.0.0.1', 6379, [
    'password' => 'secret',
    'database' => 1,
]);

$client->setLogger(function ($message) {
    echo date('[Y-m-d H:i:s] ') . $message . "\n";
});

$client->enableGracefulShutdown();
$client->loop('my_queue', new MyWorker());

$text = $message->get('text', 'default value');
if ($message->has('cmd')) { ... }
$allData = $message->toArray();