private < T > T doWithLock ( LockCallback < T > callback , String errorMessage ) throws JobPersistenceException { JedisCommands jedis = null ; try { jedis = getResource ( ) ; try { storage . waitForLock ( jedis ) ; return callback . doWithLock ( jedis ) ; } catch ( ObjectAlreadyExistsException e ) { throw e ; } catch ( Exception e ) { if ( errorMessage == null || errorMessage . isEmpty ( ) ) { errorMessage = "Job storage error." ; } throw new JobPersistenceException ( errorMessage , e ) ; } finally { storage . unlock ( jedis ) ; } } finally { if ( jedis != null && jedis instanceof Jedis ) { // only close if we're not using a JedisCluster instance ( ( Jedis ) jedis ) . close ( ) ; } } }
Perform a redis operation while lock is acquired