QueueClient.php 896 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace mall\queue;
  3. use app\common\logic\Queue;
  4. use think\facade\Cache;
  5. class QueueClient {
  6. /**
  7. * 入列
  8. * @param string $key
  9. * @param array $value
  10. */
  11. public static function push($key, $value) {
  12. if(config('cache.stores.file.type') == 'redis'){
  13. //Redis 直接写入缓存
  14. $num=Cache::get('QueueClientNum');
  15. if(!$num){
  16. $num=1;
  17. }else{
  18. $num++;
  19. }
  20. $QueueClientNum = Cache::set('QueueClientNum',$num);#缓存的数量
  21. cache('QueueClient_'.$QueueClientNum, serialize(array($key=>$value)));#写入缓存
  22. }
  23. if (config('cache.stores.file.type') == 'File') {
  24. //当前缓存类型为本地文件,则直接执行
  25. $QueueLogic = new Queue();
  26. $QueueLogic->$key($value);return;
  27. }
  28. }
  29. }
  30. ?>