PHP code example of movisio / redis-queue

1. Go to this page and download the library: Download movisio/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/ */

    

movisio / redis-queue example snippets


/** @var \Kdyby\Redis\RedisClient $redisClient */

$factory = new \Movisio\RedisQueue\Factory($redisClient);
$factory->setNamespace("Queues:MyCustomQueues"); # optional

class MyPresenter {
    /** @var \Movisio\RedisQueue\Factory @inject */
    public \Movisio\RedisQueue\Factory $queueFactory;
}

$queue = $this->queueFactory->get("QueueName");
$queueLength = $queue->push("TestMessage");

while (true) {
    $message = $queue->wait(30); // wait 30 seconds
    if (is_null($message)) {
        echo "queue is empty";
        continue; // or some fallback load from database
    }
    echo "found message: " . $message;
}

$message = $queue->pop();
if (is_null($message)) {
    echo "Queue is empty";
}