Skip to content

Commit

Permalink
fix: redis connection (#7)
Browse files Browse the repository at this point in the history
* fix: redis execute pipeline

* fix: upgrade version
  • Loading branch information
shawndenggh authored Dec 15, 2023
1 parent 3190bd5 commit 11ee41a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,13 @@ public boolean tryLock() {
final byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
final byte[] valueBytes = value.getBytes(StandardCharsets.UTF_8);
List<Object> redisResults =
redisTemplate.executePipelined(
(RedisCallback<String>) connection -> {
DefaultStringRedisConnection stringRedisConn = (DefaultStringRedisConnection) connection;
stringRedisConn.set(
keyBytes,
valueBytes,
Expiration.milliseconds(leaseMilliseconds),
RedisStringCommands.SetOption.SET_IF_ABSENT
);
stringRedisConn.get(keyBytes);
redisTemplate.executePipelined((RedisCallback<String>) connection -> {
connection.stringCommands()
.set(keyBytes, valueBytes, Expiration.milliseconds(leaseMilliseconds),
RedisStringCommands.SetOption.SET_IF_ABSENT);
connection.stringCommands().get(keyBytes);
return null;
}
);
});
Object currentLockSecret =
redisResults.size() > 1 ? redisResults.get(1) : redisResults.get(0);
return currentLockSecret != null && currentLockSecret.toString().equals(value);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.0.7
version=1.0.8

0 comments on commit 11ee41a

Please sign in to comment.