1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- namespace App\Support;
- use Predis\Client;
- class EmailQueue
- {
- const KEY = 'tbk_onlive_admin_email_queue_key';
- public static function rPush($title, $content, $emails, $sender = '')
- {
- $redisConfig = config('database.redis.default');
- $redis = new Client($redisConfig);
- // 防止大量错误导致队列堆积
- if ($redis->llen(self::KEY) > 1000) {
- return;
- }
- if (empty($emails) || !is_array($emails)) return;
- $emailData = json_encode([
- 'title' => $title,
- 'content' => $content,
- 'emails' => $emails,
- 'sender' => $sender
- ], JSON_UNESCAPED_UNICODE);
- $redis->rPush(self::KEY, $emailData);
- }
- }
|