org.springframework.integration.redis.util.RedisLockRegistry Java Examples

The following examples show how to use org.springframework.integration.redis.util.RedisLockRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisLockRunner.java    From onetwo with Apache License 2.0 6 votes vote down vote up
public static RedisLockRunner createLocker(RedisLockRegistry redisLockRegistry, String lockkey, String lockerTimeout) {
	Pair<Integer, TimeUnit> timeout = null;
	if (StringUtils.isNotBlank(lockerTimeout)) {
		timeout = LangOps.parseTimeUnit(lockerTimeout);
	}
	RedisLockRunner redisLockRunner = RedisLockRunner.builder()
													 .lockKey(lockkey)
													 .time(timeout==null?null:timeout.getKey().longValue())
													 .unit(timeout==null?null:timeout.getValue())
													 .errorHandler(e->{
														 if (e instanceof RuntimeException) {
															 throw (RuntimeException) e;
														 }
														 throw new BaseException("execute task in redislock error!", e);
													 })
													 .redisLockRegistry(redisLockRegistry)
													 .build();
	return redisLockRunner;
}
 
Example #2
Source File: RedisLockServiceAutoConfigurationTests.java    From spring-cloud-cluster with Apache License 2.0 6 votes vote down vote up
@Test
public void testChangeTimeout() throws Exception {
	EnvironmentTestUtils
			.addEnvironment(
					this.context,
					"spring.cloud.cluster.redis.lock.expireAfter:1234");
	context.register(RedisAutoConfiguration.class, RedisLockServiceAutoConfiguration.class);
	context.refresh();
	
	RedisLockService service = context.getBean(RedisLockService.class);
	RedisLockRegistry redisLockRegistry = TestUtils.readField("redisLockRegistry", service);
	String registryKey = TestUtils.readField("registryKey", redisLockRegistry);
	Long expireAfter = TestUtils.readField("expireAfter", redisLockRegistry);
	
	assertThat(registryKey, is(RedisLockService.DEFAULT_REGISTRY_KEY));
	assertThat(expireAfter, is(1234l));
}
 
Example #3
Source File: RedisConfiguration.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Bean
//	@ConditionalOnProperty(name=JFishRedisProperties.ENABLED_LOCK_REGISTRY)
	@ConditionalOnClass({RedisLockRegistry.class})
	public RedisLockRegistry redisLockRegistry(@Autowired JedisConnectionFactory jedisConnectionFactory){
		LockRegistryProperties lockRegistryProperties = redisProperties.getLockRegistry();
		String lockKey = SpringUtils.resolvePlaceholders(applicationContext, LockRegistryProperties.DEFAULT_LOCK_KEY);
		String realLockKey = lockRegistryProperties.getLockKey(lockKey);
		RedisLockRegistry lockRegistry = new RedisLockRegistry(jedisConnectionFactory, 
																realLockKey, 
																lockRegistryProperties.getExpireAfter());
		return lockRegistry;
	}
 
Example #4
Source File: RedisLockRunner.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Builder
public RedisLockRunner(RedisLockRegistry redisLockRegistry, String lockKey,
		Long time, TimeUnit unit, Consumer<Exception> errorHandler) {
	super();
	this.redisLockRegistry = redisLockRegistry;
	this.lockKey = lockKey;
	if (time!=null) {
		this.time = time;
	}
	if (unit!=null) {
		this.unit = unit;
	}
	this.errorHandler = errorHandler;
}
 
Example #5
Source File: RedisLockServiceAutoConfigurationTests.java    From spring-cloud-cluster with Apache License 2.0 5 votes vote down vote up
@Test
public void testChangeRole() throws Exception {
	EnvironmentTestUtils
			.addEnvironment(
					this.context,
					"spring.cloud.cluster.lock.role:foo");
	context.register(RedisAutoConfiguration.class, RedisLockServiceAutoConfiguration.class);
	context.refresh();
	
	RedisLockService service = context.getBean(RedisLockService.class);
	RedisLockRegistry redisLockRegistry = TestUtils.readField("redisLockRegistry", service);
	String registryKey = TestUtils.readField("registryKey", redisLockRegistry);
	
	assertThat(registryKey, is("foo"));
}
 
Example #6
Source File: RedisLockConfiguration.java    From spring-boot-study with Apache License 2.0 4 votes vote down vote up
@Bean
public RedisLockRegistry redisLockRegistry(RedisConnectionFactory redisConnectionFactory) {
  return new RedisLockRegistry(redisConnectionFactory, "spring-cloud", 5000L);
}
 
Example #7
Source File: RedisLockRunner.java    From onetwo with Apache License 2.0 2 votes vote down vote up
/****
 * 
 * @deprecated 写错了单词……
 * @author weishao zeng
 * @param redisLockRegistry
 * @param lockkey
 * @param lockerTimeout
 * @return
 */
@Deprecated
public static RedisLockRunner createLoker(RedisLockRegistry redisLockRegistry, String lockkey, String lockerTimeout) {
	return createLocker(redisLockRegistry, lockkey, lockerTimeout);
}
 
Example #8
Source File: RedisLockService.java    From spring-cloud-cluster with Apache License 2.0 2 votes vote down vote up
/**
 * Instantiates a new redis lock service.
 *
 * @param connectionFactory the redis connection factory
 * @param registryKey The key prefix for locks.
 */
public RedisLockService(RedisConnectionFactory connectionFactory, String registryKey) {
	this.redisLockRegistry = new RedisLockRegistry(connectionFactory, registryKey);
}
 
Example #9
Source File: RedisLockService.java    From spring-cloud-cluster with Apache License 2.0 2 votes vote down vote up
/**
 * Instantiates a new redis lock service.
 *
 * @param connectionFactory the redis connection factory
 * @param expireAfter The expiration in milliseconds.
 */
public RedisLockService(RedisConnectionFactory connectionFactory, long expireAfter) {
	this.redisLockRegistry = new RedisLockRegistry(connectionFactory, DEFAULT_REGISTRY_KEY, expireAfter);
}
 
Example #10
Source File: RedisLockService.java    From spring-cloud-cluster with Apache License 2.0 2 votes vote down vote up
/**
 * Instantiates a new redis lock service.
 *
 * @param connectionFactory the redis connection factory
 * @param registryKey The key prefix for locks.
 * @param expireAfter The expiration in milliseconds.
 */
public RedisLockService(RedisConnectionFactory connectionFactory, String registryKey, long expireAfter) {
	this.redisLockRegistry = new RedisLockRegistry(connectionFactory, registryKey, expireAfter);
}