-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($starter): support dynamic autoconfiguration for Redis lock
- Loading branch information
1 parent
2e0ce94
commit f03a337
Showing
2 changed files
with
48 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...n/java/com/jmsoftware/maf/springcloudstarter/redis/RedisDistributedLockConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.jmsoftware.maf.springcloudstarter.redis; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.integration.redis.util.RedisLockRegistry; | ||
|
||
/** | ||
* <h1>RedisDistributedLockConfiguration</h1> | ||
* <p> | ||
* Change description here. | ||
* | ||
* @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com, 2/26/22 11:19 PM | ||
**/ | ||
@Slf4j | ||
@ConditionalOnClass({RedisLockRegistry.class}) | ||
public class RedisDistributedLockConfiguration { | ||
private static final String REGISTRY_KEY = "redis-lock"; | ||
|
||
/** | ||
* Redis distributed lock registry. | ||
* | ||
* @param redisConnectionFactory the redis connection factory | ||
* @return the redis lock registry | ||
* @see | ||
* <a href='https://docs.spring.io/spring-integration/docs/current/reference/html/redis.html#redis-lock-registry'>Redis Lock Registry</a> | ||
*/ | ||
@Bean(destroyMethod = "destroy") | ||
@ConditionalOnClass({RedisLockRegistry.class}) | ||
public RedisLockRegistry redisLockRegistry(RedisConnectionFactory redisConnectionFactory) { | ||
val redisLockRegistry = new RedisLockRegistry(redisConnectionFactory, REGISTRY_KEY); | ||
log.warn("RedisLockRegistry bean is created. {}", redisLockRegistry); | ||
return redisLockRegistry; | ||
} | ||
|
||
@Bean | ||
@ConditionalOnClass({RedisLockRegistry.class}) | ||
public RedisDistributedLockDemoController redisDistributedLockDemoController( | ||
RedisLockRegistry redisLockRegistry | ||
) { | ||
log.warn("RedisDistributedLockDemoController is created"); | ||
return new RedisDistributedLockDemoController(redisLockRegistry); | ||
} | ||
} |