PHP code example of zoon / requeue

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

    

zoon / requeue example snippets


$redis = new \Redis();
if (!$redis->connect('127.0.0.1')) {
    exit('no connection');
}
$queue = createQueue($redis);

function createQueue(\Redis $connection): \Zoon\ReQueue\Queue {
	$redisAdapter = new \Zoon\ReQueue\RedisAdapter($connection);
	return new \Zoon\ReQueue\Queue($redisAdapter);
}

$queue->push(new \Zoon\ReQueue\Message('id', time() + 3600, 'data'));

$queue->update('id', function (?\Zoon\ReQueue\Message $old) {
	$time = ($old === null ? time() + 3600 : $old->getTimestamp() + 600);
	$data = ($old === null ? 'data' : $old->getData() . '+new');
	return new \Zoon\ReQueue\MessageData($time, $data);
});

printf("count: %d\n", $queue->count());

// count: 1

$timestampRange = new \Zoon\ReQueue\TimestampRange(null, time() + 3600 + 600);
$message = $queue->pop($timestampRange);
if ($message !== null) {
	printf("id: %s\n", $message->getId());
	printf("timestamp: %d\n", $message->getTimestamp());
	printf("data: %s\n", $message->getData());
}

// id: id
// timestamp: 1575040030
// data: data+new

$queue->clear();