slaszu/redismq 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

slaszu/redismq

Composer 安装命令:

composer require slaszu/redismq

包简介

Implementation of Pattern 'Reliable queue', using php and Redis

README 文档

README

The idea is taken from Redis Documentation

Install by composer

composer require slaszu/redismq

Important

All examples you can find in tests/UsecaseTest.php

Configuration

This library use Predis to connect to Redis server. So we need predis object in examples below

$this->client = new \Predis\Client([
	'scheme' => 'tcp',
	'host' => REDIS_SERVER_HOST,
	'port' => REDIS_SERVER_PORT,
]);

Create a queue

$queue = new \RedisMq\Queue($this->client, $name);

Add task (message) to queue

// eg. this is message with array, but message could be a simple string either
$message = new \RedisMq\Message([
    'x' => 2,
    'string' => 'Message number 2',
    'rand' => rand(10000, 99999)
]);
$queue->addMessage($message);

Play with tasks

Get list of tasks to process

$taskQty = 100;
$taskList = $queue->getTaskList($taskQty);

Get task detail

$task = $taskList->getTask();
$message = $task->getMessage();
$body = $messageArray->getBody();

//variable $body is an array given in section "Add task (message) to queue"

Confirm task

$task = $taskList->getTask();

/*
 * .....
 * proccess message (task details) from task and if is all right then confirm this task
 * .....
 */

$task->confirm();

Task is removed from queue after confirmation.

Repair queue

When you get TaskList from Queue, then Tasks are moved from Queue to TaskList. Task which are in TaskList not exist any longer in Queue.

In some situations you may want to move task from TaskList back to Queue. To do this use repairTaskLists method. This method takes one param (time in seconds). This is the minimum time that has elapsed since the creation of TaskLists. This method check all Task Lists that was created from Queue.

Important: if all Tasks from TaskList are confirmed, then this TaskList is empty and Redis remove this task immediately.

$queue = new \RedisMq\Queue($this->client, $name);
$queue->repairTaskLists(60); // 60 is time in seconds

统计信息

  • 总下载量: 696
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-06-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固