package cn.iocoder.yudao.module.system.util.redis;

import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

@Component
public class RedissonUtils {

    @Resource
    private RedissonClient redissonClient;

    /**
     * 获取redisson锁
     * @param keys 同时锁多个key
     * @return
     */
    public RLock getLocks(Set<String> keys){
        RLock[] lockArray = keys.stream().map(key -> redissonClient.getLock(key)).toArray(RLock[]::new);
        return redissonClient.getMultiLock(lockArray);
    }

    public RLock getLock(String key){
        return redissonClient.getLock(key);
    }

}
