SimpleRedisLock extends AbstractSimpleLock { @Override protected boolean release(final String key, final String storeId, final String token) { final var singletonKeyList = Collections.singletonList(storeId + ":" + key); final var released = stringRedisTemplate.execute(lockReleaseScript, singletonKeyList, token); if (released) { log.debug("Release script deleted the record for key {} with token {} in store {}", key, token, storeId); } else { log.error("Release script failed for key {} with token {} in store {}", key, token, storeId); } return released; } SimpleRedisLock(final Supplier<String> tokenSupplier, final StringRedisTemplate stringRedisTemplate);   }
@Test public void shouldRelease() { redisTemplate.opsForValue().set("locks:1", "abc"); lock.release(Collections.singletonList("1"), "locks", "abc"); assertThat(redisTemplate.opsForValue().get("locks:1")).isNull(); }
@Test public void shouldNotRelease() { redisTemplate.opsForValue().set("locks:1", "def"); lock.release(Collections.singletonList("1"), "locks", "abc"); assertThat(redisTemplate.opsForValue().get("locks:1")).isEqualTo("def"); }