暂无描述

EmailQueue.php 751B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Support;
  3. use Predis\Client;
  4. class EmailQueue
  5. {
  6. const KEY = 'tbk_onlive_admin_email_queue_key';
  7. public static function rPush($title, $content, $emails, $sender = '')
  8. {
  9. $redisConfig = config('database.redis.default');
  10. $redis = new Client($redisConfig);
  11. // 防止大量错误导致队列堆积
  12. if ($redis->llen(self::KEY) > 1000) {
  13. return;
  14. }
  15. if (empty($emails) || !is_array($emails)) return;
  16. $emailData = json_encode([
  17. 'title' => $title,
  18. 'content' => $content,
  19. 'emails' => $emails,
  20. 'sender' => $sender
  21. ], JSON_UNESCAPED_UNICODE);
  22. $redis->rPush(self::KEY, $emailData);
  23. }
  24. }