Skip to content

Commit 94100c0

Browse files
committed
Using redis spring 2 features
1 parent e8f9c01 commit 94100c0

File tree

1 file changed

+2
-3
lines changed
  • providers/redis/shedlock-provider-redis-spring/src/main/java/net/javacrumbs/shedlock/provider/redis/spring

1 file changed

+2
-3
lines changed

providers/redis/shedlock-provider-redis-spring/src/main/java/net/javacrumbs/shedlock/provider/redis/spring/RedisLockProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ public RedisLockProvider(RedisConnectionFactory redisConn, String environment) {
5353

5454
@Override
5555
public Optional<SimpleLock> lock(LockConfiguration lockConfiguration) {
56-
5756
String key = buildKey(lockConfiguration.getName(), this.environment);
5857
RedisConnection redisConnection = null;
5958
try {
6059
redisConnection = redisConnectionFactory.getConnection();
61-
if (redisConnection.setNX(key.getBytes(), buildValue())) {
62-
redisConnection.pExpire(key.getBytes(), getMsUntil(lockConfiguration.getLockAtMostUntil()));
60+
Expiration expiration = getExpiration(lockConfiguration.getLockAtMostUntil());
61+
if (redisConnection.set(key.getBytes(), buildValue(), expiration, SetOption.SET_IF_ABSENT)) {
6362
return Optional.of(new RedisLock(key, redisConnectionFactory, lockConfiguration));
6463
} else {
6564
return Optional.empty();

0 commit comments

Comments
 (0)