Created
          March 17, 2014 16:33 
        
      - 
      
- 
        Save TheDeveloper/9602872 to your computer and use it in GitHub Desktop. 
    Set a lock in Redis
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | -- | |
| -- Set a lock | |
| -- | |
| -- KEYS[1] - key | |
| -- KEYS[2] - ttl in ms | |
| -- KEYS[3] - lock content | |
| local key = KEYS[1] | |
| local ttl = KEYS[2] | |
| local content = KEYS[3] | |
| local lockSet = redis.call('setnx', key, content) | |
| if lockSet == 1 then | |
| redis.call('pexpire', key, ttl) | |
| end | |
| return lockSet | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment