Files

70 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2022-08-20 17:05:05 +08:00
<?php
declare (strict_types=1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\queue\redis;
use support\Log;
use Webman\RedisQueue\Redis;
use Webman\RedisQueue\Client;
2022-08-20 17:05:05 +08:00
/**
* 队列任务
* @package app\queue\redis
* @author meystack
* @date 2022-11-20
*/
class Push
2022-08-20 17:05:05 +08:00
{
/**
* api推送
2022-11-28 19:11:12 +08:00
* @var mixed
2022-08-20 17:05:05 +08:00
*/
2022-11-28 19:11:12 +08:00
protected mixed $api;
2022-08-20 17:05:05 +08:00
/**
* 同步推送
* @param $name
* @param $data
* @param int $delay
* @return bool
2022-08-20 17:05:05 +08:00
*/
public static function queue($name, $data, int $delay = 0): bool
2022-08-20 17:05:05 +08:00
{
try {
// 投递消息
Redis::send($name, $data, $delay);
} catch (\Throwable $th) {
Log::info('redis push error:' . $th->getMessage());
return false;
}
return true;
2022-08-20 17:05:05 +08:00
}
/**
* 异步推送
* @param $name
* @param $data
* @param int $delay
* @return bool
2022-08-20 17:05:05 +08:00
*/
public static function client($name, $data, int $delay = 0): bool
2022-08-20 17:05:05 +08:00
{
try {
// 投递消息
Client::send($name, $data, $delay);
} catch (\Throwable $th) {
Log::info('redis Client async error:' . $th->getMessage());
return false;
}
return true;
2022-08-20 17:05:05 +08:00
}
}