zoon/requeue

This package is abandoned and no longer maintained. No replacement package was suggested.

Redis delayed message queue without locks

1.0.3 2023-05-17 22:31 UTC

This package is auto-updated.

Last update: 2024-03-13 12:42:26 UTC


README

Redis delayed message queue without locks.

Quick start

Install

composer require zoon/requeue

Note: Requires Redis >= 2.2.0

Example

Initialize

$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);
}

Push

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

Update

$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);
});

Count

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

Pop

$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

Clear

$queue->clear();