//package com.ssm.annotation;
//
//import com.ssm.manage.entity.SmsException;
//import com.ssm.manage.response.ResponseCode;
//import lombok.SneakyThrows;
//import org.apache.poi.ss.formula.functions.T;
//import org.redisson.api.RLock;
//import org.redisson.api.RedissonClient;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.concurrent.TimeUnit;
//
//@Component
//public class RedissonLockService {
//    @Autowired
//    private RedissonClient redissonClient;
//
//    @SneakyThrows
//    public <T> T  lock(String key, int timeout, TimeUnit timeUnit, Supplier<T> supplier) throws SmsException {
//        RLock lock = redissonClient.getLock(key);
//        boolean tryLock = lock.tryLock(timeout,timeUnit);
//        if (!tryLock) {
//            throw new SmsException(ResponseCode.MSG,"请求太频繁了");
//        }
//        try {
//            return supplier.get();
//        }finally {
//            lock.unlock();
//        }
//    }
//
//
//    @FunctionalInterface
//    public interface Supplier<T> {
//
//        /**
//         * Gets a result.
//         *
//         * @return a result
//         */
//        T get() throws Throwable;
//    }
//}
