package com.easyagu.liwei.list;
import redis.clients.jedis.Jedis;
import java.util.List;
/**
*
*/
public class SendMailDemo {
private Jedis jedis=new Jedis("127.0.0.1");
/**
* 发送邮件任务入队列
* @param sendMailTask
*/
public void enqueueSendMailTask(String sendMailTask){
jedis.lpush("send_main_task_queue",sendMailTask);
}
/**
* 阻塞式获取发送邮件任务
* @return
*/
public List<String> takeSendMailTask(){
//阻塞多少秒
return jedis.brpop(2,"send_main_task_queue");
}
public static void main(String[] args) {
SendMailDemo demo=new SendMailDemo();
System.out.println("尝试阻塞式的获取发送邮件任务....");
List<String> strings = demo.takeSendMailTask();
System.out.println(strings);
demo.enqueueSendMailTask("第一个邮件发送任务");
List<String> task = demo.takeSendMailTask();
System.out.println(task);
}
}