Skip to content

a way to achieve distributed lock by redis module

License

Notifications You must be signed in to change notification settings

wujunwei/redlock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jk jk jk jk

redlock

a way to achieve distributed lock by redis module

redis

build

git clone  --depth=1 git@github.com:redis/redis.git
cd redis
git clone https://github.com/wujunwei/redlock
cd redlock
make

install

//run it in redis cli or add it into the conf
module load redlock.so

How to use

  • slock.lock lock_key (expire_time)
    The command will return result immediately ,you shall call lock in a while or give up locking
  • slock.unlock key
    Release the write-lock, if the lock wasn't been created by the same client, it will fail with 0.
  • slock.rlock key (expire_time)
    Acquire the read-lock(share lock), if the lock wasn't been created by the same client, it will fail with 0.
  • slock.runlock key
    Reduce the readers count of read-lock(share lock), if the readers count equal to 0 ,it will be released.
    This command won't be limited by the different client. if the lock isn't created by the command "slock.rlock", it will fail with 0.
  • slock.info key
    This command will return an array with four integers, first is the client id , second is the time when lock was created , the third one is whether the lock is write-lock or not (reply with 0 present lock fail, and otherwise success) and the last one is the count of require the read lock(about the lock command ,it 's always 0).

PLEASE NOTE: The module recommend to be used for stand-alone or Sharding mode,use it carefully.