```
//创建适配器,适配器有多种Database,Redis,Sync,Topthink. 自动根据配置加载对应的适配器类
private static function buildConnector()
{
$options = Config::get('queue'); //配置文件在application\extra\queue.php
$type = !empty($options['connector']) ? $options['connector'] : 'Sync';
if (!isset(self::$connector)) {
$class = false !== strpos($type, '\\') ? $type : '\\think\\queue\\connector\\' . Str::studly($type);
self::$connector = new $class($options);
}
return self::$connector;
}
//调用对应适配器里面的静态方法
public static function __callStatic($name, $arguments)
{
return call_user_func_array([self::buildConnector(), $name], $arguments);
}
```
使用 [魔术方法](https://www.php.net/manual/zh/language.oop5.overloading.php#object.callstatic) __callStatic调用这个类中不存在的静态函数;
主要是这几个函数
\* @method static push($job, $data = '', $queue = null) //创建任务后立刻执行
\* @method static later($delay, $job, $data = '', $queue = null) //创建任务后N秒再执行
\* @method static pop($queue = null) //
\* @method static marshal()
例子:
```
//创建一个任务,延迟10秒后执行
$test= \think\Queue::later(10, '\addons\shopro\job\InterestJob@execCycleUserInterestJob',$data, 'shopro');
```
在调用later()时并不存在这个函数,而是调用__callStatic,进而调用相应的适配器里面的later函数;
然后用redis管理器查看redis里面的数据:

可以看到'目录'层次是 queues: TP的队列 , shopro:队列名称,delayed:延迟类任务 ;
在delayed里面就是保存着所有延迟任务的数据;
```
{"job":"\\addons\\shopro\\job\\InterestJob@execCycleUserInterestJob","data":{"kind":"cycle","cycle":"month"},"id":"lgrwTERrEwJpwIYJlvu0p8OwhTBT9WWP","attempts":1}
```
job:要执行的任务目标类和函数;
data一般是json ,用的时候转回数组;
id:随机32位字符串;
attempts:任务重试次数,默认是1(因为在创建,就设定为1)
- FA的JS调用机制说明
- FA的JS之Fast.api逐个详解
- FA页面渲染时后端传递数据给前端的方式
- FA的ajax查询数据的前后台流程
- FA特有的函数解释
- FA的鉴权Auth类
- extend\fast\Auth.php详解
- application\admin\library\Auth.php详解
- application\common\library\Auth.php详解
- FA的Token机制
- FA管理员(后台)的权限机制
- FA用户(前台和API)的权限机制
- FA在前台模板文件中进行鉴权
- FA的登录页面
- TP类Hook:钩子机制
- TP类Lang:多语言机制
- TP类Config:参数配置机制
- TP类Request:请求类
- TP的模型关联详解
- think-queue队列组件
- Queue.php
- \queue\Connector.php
- \queue\connector\Redis.php
- \queue\Job.php
- queue\job\Redis.php
- PHP规则:正则表达式
- PHP规则:闭包与匿名函数
- 项目架构说明
- 代码架构
- TP数据库where条件的各种写法
