Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

zoonru/requeue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReQueue

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();