33import lombok .AllArgsConstructor ;
44import lombok .Data ;
55import lombok .RequiredArgsConstructor ;
6- import org .springframework .data .redis .core .StringRedisTemplate ;
6+ import org .springframework .data .redis .core .RedisTemplate ;
77import org .springframework .stereotype .Component ;
88import top .cadecode .uniboot .common .plugin .cache .exception .RedisLockException ;
99
2323@ RequiredArgsConstructor
2424public class RedisLockKit {
2525
26- private final StringRedisTemplate redisTemplate ;
26+ private final RedisTemplate < String , Object > redisTemplate ;
2727
2828 private final Map <String , LockContent > contentMap = new ConcurrentHashMap <>();
2929
@@ -39,7 +39,7 @@ public void lock(String name) {
3939 lock (name , "" );
4040 }
4141
42- public void lock (String name , String value ) {
42+ public void lock (String name , Object value ) {
4343 if (checkReentrant (name )) {
4444 storeLock (name , null , true );
4545 return ;
@@ -62,7 +62,7 @@ public boolean tryLock(String name) {
6262 return tryLock (name , "" );
6363 }
6464
65- public boolean tryLock (String name , String value ) {
65+ public boolean tryLock (String name , Object value ) {
6666 if (checkReentrant (name )) {
6767 storeLock (name , null , true );
6868 return true ;
@@ -82,7 +82,7 @@ public boolean tryLock(String name, long timeout, TimeUnit timeUnit) {
8282 return tryLock (name , "" , timeout , timeUnit );
8383 }
8484
85- public boolean tryLock (String name , String value , long timeout , TimeUnit timeUnit ) {
85+ public boolean tryLock (String name , Object value , long timeout , TimeUnit timeUnit ) {
8686 if (checkReentrant (name )) {
8787 storeLock (name , null , true );
8888 return true ;
@@ -190,7 +190,7 @@ private void storeLock(String name, ScheduledFuture<?> future, boolean reentrant
190190 * @param name 锁名称
191191 * @return 是否设置成功
192192 */
193- private boolean tryLock0 (String name , String value ) {
193+ private boolean tryLock0 (String name , Object value ) {
194194 Boolean success = redisTemplate .opsForValue ().setIfAbsent (name , value , 30 , TimeUnit .SECONDS );
195195 if (Objects .equals (success , false )) {
196196 return false ;
@@ -207,7 +207,7 @@ private boolean tryLock0(String name, String value) {
207207 * @param name 锁名称
208208 * @return ScheduledFuture
209209 */
210- private ScheduledFuture <?> renewLock (String name , String value ) {
210+ private ScheduledFuture <?> renewLock (String name , Object value ) {
211211 // 有效期设置为 30s,每 15 秒重置
212212 return executor .scheduleAtFixedRate (() -> {
213213 Boolean success = redisTemplate .opsForValue ().setIfPresent (name , value , 30 , TimeUnit .SECONDS );
0 commit comments