CRedisQuery.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fec\helpers;
  10. use Yii;
  11. use yii\base\InvalidConfigException;
  12. use yii\redis\Connection;
  13. use fec\helpers\credisqueue\Queue;
  14. use fec\helpers\credisqueue\Job;
  15. /**
  16. * @author Terry Zhao <2358269014@qq.com>
  17. * @since 1.0
  18. */
  19. class CRedisQueue extends Queue
  20. {
  21. /*
  22. 在使用之前,您需要先进行配置如下:
  23. 'components' => [
  24. 'queue' => [
  25. 'class' => 'fec\component\RedisQueue',
  26. ],
  27. ],
  28. 'controllerMap' => [
  29. 'queue' => 'fec\component\redisqueue\QueueController'
  30. ],
  31. */
  32. /*
  33. 1. 定义TestJob文件
  34. 实现run方法()
  35. 2. 执行命令行:./yii queue/listen MyTestQueue
  36. 3. 使用push方法,把参数传入
  37. $job = '\fec\component\redisqueue\TestJob';
  38. $data = ['a', 'b', 'c'];
  39. $queue = 'MyTestQueue';
  40. CRedisQuery::push($job,$data);
  41. \fec\component\redisqueue\TestJob 里面的run方法将会被执行
  42. */
  43. public static function push($job,$data,$queue = null){
  44. //return Yii::$app->queue->push('\fec\component\redisqueue\TestJob', ['a', 'b', 'c']);
  45. return Yii::$app->queue->push($job,$data,$queue);
  46. }
  47. }