public boolean lock ( T jedis ) { UUID lockId = UUID . randomUUID ( ) ; final String setResponse = jedis . set ( redisSchema . lockKey ( ) , lockId . toString ( ) , "NX" , "PX" , lockTimeout ) ; boolean lockAcquired = ! isNullOrEmpty ( setResponse ) && setResponse . equals ( "OK" ) ; if ( lockAcquired ) { // save the random value used to lock so that we can successfully unlock later lockValue = lockId ; } return lockAcquired ; }
Attempt to acquire a lock