@@ -434,11 +434,6 @@ protected abstract boolean tryRedisLockInner(long time, long expireAfter)
434434 */
435435 protected abstract boolean removeLockKeyInnerUnlink ();
436436
437- /**
438- * Unlock the lock using the delete method in redis.
439- */
440- protected abstract boolean removeLockKeyInnerDelete ();
441-
442437 @ Override
443438 public final void lock () {
444439 this .lock (RedisLockRegistry .this .expireAfter );
@@ -583,7 +578,7 @@ public final void unlock() {
583578 private void removeLockKey () {
584579 boolean unlinkResult = removeLockKeyInnerUnlink ();
585580 if (unlinkResult ) {
586- // Lock key successfully unlinked
581+ // Lock key successfully removed
587582 stopRenew ();
588583 } else {
589584 throw new ConcurrentModificationException ("Lock was released in the store due to expiration. " +
@@ -676,21 +671,9 @@ private final class RedisPubSubLock extends RedisLock {
676671 return false
677672 """ ;
678673
679- private static final String DELETE_UNLOCK_SCRIPT = """
680- local lockClientId = redis.call('GET', KEYS[1])
681- if (lockClientId == ARGV[1] and redis.call('DEL', KEYS[1]) == 1) then
682- redis.call('PUBLISH', ARGV[2], KEYS[1])
683- return true
684- end
685- return false
686- """ ;
687-
688674 private static final RedisScript <Boolean >
689675 UNLINK_UNLOCK_REDIS_SCRIPT = new DefaultRedisScript <>(UNLINK_UNLOCK_SCRIPT , Boolean .class );
690676
691- private static final RedisScript <Boolean >
692- DELETE_UNLOCK_REDIS_SCRIPT = new DefaultRedisScript <>(DELETE_UNLOCK_SCRIPT , Boolean .class );
693-
694677 private RedisPubSubLock (String path ) {
695678 super (path );
696679 }
@@ -703,17 +686,8 @@ protected boolean tryRedisLockInner(long time, long expireAfter)
703686
704687 @ Override
705688 protected boolean removeLockKeyInnerUnlink () {
706- return removeLockKeyWithScript (UNLINK_UNLOCK_REDIS_SCRIPT );
707- }
708-
709- @ Override
710- protected boolean removeLockKeyInnerDelete () {
711- return removeLockKeyWithScript (DELETE_UNLOCK_REDIS_SCRIPT );
712- }
713-
714- private boolean removeLockKeyWithScript (RedisScript <Boolean > redisScript ) {
715689 return Boolean .TRUE .equals (RedisLockRegistry .this .redisTemplate .execute (
716- redisScript , Collections .singletonList (this .lockKey ),
690+ UNLINK_UNLOCK_REDIS_SCRIPT , Collections .singletonList (this .lockKey ),
717691 RedisLockRegistry .this .clientId , RedisLockRegistry .this .unLockChannelKey ));
718692 }
719693
@@ -825,20 +799,9 @@ private final class RedisSpinLock extends RedisLock {
825799 return false
826800 """ ;
827801
828- private static final String DELETE_UNLOCK_SCRIPT = """
829- local lockClientId = redis.call('GET', KEYS[1])
830- if lockClientId == ARGV[1] then
831- redis.call('DEL', KEYS[1])
832- return true
833- end
834- return false
835- """ ;
836-
837802 private static final RedisScript <Boolean >
838803 UNLINK_UNLOCK_REDIS_SCRIPT = new DefaultRedisScript <>(UNLINK_UNLOCK_SCRIPT , Boolean .class );
839804
840- private static final RedisScript <Boolean >
841- DELETE_UNLOCK_REDIS_SCRIPT = new DefaultRedisScript <>(DELETE_UNLOCK_SCRIPT , Boolean .class );
842805
843806 private RedisSpinLock (String path ) {
844807 super (path );
@@ -865,17 +828,8 @@ protected boolean tryRedisLockInner(long time, long expireAfter) throws Interrup
865828
866829 @ Override
867830 protected boolean removeLockKeyInnerUnlink () {
868- return removeLockKeyWithScript (UNLINK_UNLOCK_REDIS_SCRIPT );
869- }
870-
871- @ Override
872- protected boolean removeLockKeyInnerDelete () {
873- return removeLockKeyWithScript (DELETE_UNLOCK_REDIS_SCRIPT );
874- }
875-
876- private boolean removeLockKeyWithScript (RedisScript <Boolean > redisScript ) {
877831 return Boolean .TRUE .equals (RedisLockRegistry .this .redisTemplate .execute (
878- redisScript , Collections .singletonList (this .lockKey ),
832+ UNLINK_UNLOCK_REDIS_SCRIPT , Collections .singletonList (this .lockKey ),
879833 RedisLockRegistry .this .clientId ));
880834 }
881835
0 commit comments