Skip to content

Distributed lock implements using Redis and ZooKeeper

Notifications You must be signed in to change notification settings

wynn5a/distributed-locks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

distributed-locks

Distributed locking based on zookeeper(ZooKeeperLock) and Redis(RedisLock)

ZooKeeperLock

Implement based on the recipes of ZooKeeper.

Usage:

 ZookeeperLock lock = new ZookeeperLock(new ZooKeeperClient("127.0.0.1:2183"), resource);
 try {
   lock.lock();
   Thread.currentThread().sleep(5000);
   lock.unlock();
 } catch (InterruptedException e) {
   e.printStackTrace();
 }

RedisLock

Implement based on REDLOCK algorithm.

Usage:

RedisLock lock = new RedisLock(new RedisNodes("127.0.0.1:3679", "127.0.0.1:3678","127.0.0.1:3677"),"LOCK", 60000);
try {
    lock.lock();
    doingJob();
    lock.unlock();
} catch (Exception e) {
    //doing something
}

About

Distributed lock implements using Redis and ZooKeeper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages