Skip to content

redis lock -- 基于Redis并实现了Lock接口的Lock

Notifications You must be signed in to change notification settings

guqiyao/redis-lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 

Repository files navigation

redis-lock

基于Redis并简单实现了java.util.concurrent.locks.Lock接口的Lock

当前版本: 1.0.2

get it

Maven

    <dependency>
        <groupId>io.github.guqiyao</groupId>
        <artifactId>redis-lock</artifactId>
        <version>${version}</version>
    </dependency>

使用

spring boot

  • 配置

RedisTemplate

    @Bean
    public RedisLockOperation redisLockOperation(RedisTemplate<String, String> redisTemplate) {
        return new RedisTemplateOperation<>(redisTemplate);
    }

Jedis

    @Bean
    public RedisLockOperation redisLockOperation(JedisPool jedisPool) {
        return new JedisOperation(jedisPool);
    }
  • 使用
    public class TestServiceImpl {
    
        @Autowired
        private ReentrantRedisLock reentrantRedisLock;
        
        public  void use() {
            String key = "test_ley";
            //指定过期时间为10秒
            Lock lock = reentrantRedisLock.getLock(key, 10);
            
            try {
                lock.lock();
                //TODO
            } finally {
                lock.unlock();
            }
        }
    
    }
  • 注:
  1. lockInterruptibly 与 newCondition 方法未实现;

About

redis lock -- 基于Redis并实现了Lock接口的Lock

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages