package com.itheima.service.impl;

import com.itheima.service.RedPacketService;
import com.itheima.util.Constant;
import org.apache.tomcat.util.bcel.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/*****
 * @Author: http://www.itheima.com
 * @Description: com.itheima.service.impl.RedPacketServiceImpl
 ****/
@Service
public class RedPacketServiceImpl implements RedPacketService {

    @Autowired
    private RedisTemplate redisTemplate;

    /****
     * 抢红包
     * @return
     */
    @Override
    public Double grab() {
        //从队列中获取一条记录
        Object money = redisTemplate.boundListOps(Constant.MONEY_QUEUE_NAME).rightPop();
        if(money==null){
            return 0.0;
        }
        return Double.valueOf(money.toString());
    }
}
