package com.easyagu.liwei.list;
import redis.clients.jedis.Jedis;
/**
* 秒杀案例
*/
public class SeckillDemo {
public static void main(String[] args) {
SeckillDemo demo = new SeckillDemo();
for(int i=0;i<10;i++){
demo.enqueueSecKillRequest("第"+(i+1)+"个秒杀请求");
}
while (true){
String sek = demo.dequeueSecKillRequest();
if(sek==null||"".equals(sek)||"null".equals(sek)){
break;
}
System.out.println(sek);
}
}
private Jedis jedis=new Jedis("127.0.0.1");
/**
* 秒杀抢购请求出队
* @return
*/
public String dequeueSecKillRequest(){
return jedis.rpop("sec_kill_request_queue");
}
/**
* 秒杀抢购请求入队
* @param seckillRequest
*/
public void enqueueSecKillRequest(String seckillRequest){
jedis.lpush("sec_kill_request_queue",seckillRequest);
}
}