From 11ee41abb7d0b569e1442340dba3b56b5dee1ab1 Mon Sep 17 00:00:00 2001 From: Shawn Deng Date: Fri, 15 Dec 2023 14:55:53 +0800 Subject: [PATCH] fix: redis connection (#7) * fix: redis execute pipeline * fix: upgrade version --- .../RedisTemplateSimpleDistributedLock.java | 18 ++++++------------ gradle.properties | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/com/vikadata/social/core/RedisTemplateSimpleDistributedLock.java b/common/src/main/java/com/vikadata/social/core/RedisTemplateSimpleDistributedLock.java index e91c57c..b68e597 100644 --- a/common/src/main/java/com/vikadata/social/core/RedisTemplateSimpleDistributedLock.java +++ b/common/src/main/java/com/vikadata/social/core/RedisTemplateSimpleDistributedLock.java @@ -80,19 +80,13 @@ public boolean tryLock() { final byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); final byte[] valueBytes = value.getBytes(StandardCharsets.UTF_8); List redisResults = - redisTemplate.executePipelined( - (RedisCallback) connection -> { - DefaultStringRedisConnection stringRedisConn = (DefaultStringRedisConnection) connection; - stringRedisConn.set( - keyBytes, - valueBytes, - Expiration.milliseconds(leaseMilliseconds), - RedisStringCommands.SetOption.SET_IF_ABSENT - ); - stringRedisConn.get(keyBytes); + redisTemplate.executePipelined((RedisCallback) 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); diff --git a/gradle.properties b/gradle.properties index 8cf3c72..6c81e43 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=1.0.7 \ No newline at end of file +version=1.0.8 \ No newline at end of file