org.springframework.data.redis.support.atomic.RedisAtomicLong Java Examples

The following examples show how to use org.springframework.data.redis.support.atomic.RedisAtomicLong. 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: LoginSecurityService.java    From seezoon-framework-all with Apache License 2.0 7 votes vote down vote up
public Long getLoginFailCount(String loginName) {
	try {
		// spring data increment 有bug 故采用这种方式
		RedisAtomicLong counter = new RedisAtomicLong(LOCK_PREFIX + loginName,
				redisTemplate.getConnectionFactory());
		return counter.get();
	} finally {
		redisTemplate.expire(LOCK_PREFIX + loginName, 24, TimeUnit.HOURS);
	}
}
 
Example #2
Source File: LoginSecurityService.java    From seezoon-framework-all with Apache License 2.0 7 votes vote down vote up
public Long incrementLoginFailTimes(String loginName) {
	try {
		RedisAtomicLong counter = new RedisAtomicLong(LOCK_PREFIX + loginName,
				redisTemplate.getConnectionFactory());
		return counter.incrementAndGet();
	} finally {
		redisTemplate.expire(LOCK_PREFIX + loginName, 24, TimeUnit.HOURS);
	}
}
 
Example #3
Source File: SequenceServiceImpl.java    From sctalk with Apache License 2.0 7 votes vote down vote up
@Override
public Long addAndGetLong(String key, int step) {
    RedisAtomicLong counter = 
            new RedisAtomicLong(key, redisTemplate.getConnectionFactory()); 
    Long sequence =  counter.addAndGet(step);
    
    return sequence; 
}
 
Example #4
Source File: RedisIdGenerator.java    From sagacity-sqltoy with Apache License 2.0 6 votes vote down vote up
/**
 * @todo 批量获取key值,并指定过期时间
 * @param key
 * @param increment
 * @param expireTime
 * @return
 */
public long generateId(String key, int increment, Date expireTime) {
	RedisAtomicLong counter = new RedisAtomicLong(GLOBAL_ID_PREFIX.concat(key),
			redisTemplate.getConnectionFactory());
	// 设置过期时间
	if (expireTime != null) {
		counter.expireAt(expireTime);
	}
	// 设置提取多个数量
	if (increment > 1) {
		return counter.addAndGet(increment);
	}
	return counter.incrementAndGet();
}
 
Example #5
Source File: UploadServiceImpl.java    From spring-boot-cookbook with Apache License 2.0 5 votes vote down vote up
@Override
public void countUploadFiles() {
    String key = "UPLOADED_FILE_NUM";
    RedisAtomicLong redisAtomicLong = new RedisAtomicLong(key, redisTemplate.getConnectionFactory());
    Long num = redisAtomicLong.incrementAndGet();
    LOGGER.info("uploaded {} files", num);
}
 
Example #6
Source File: ChatWebSocketHandler.java    From spring-redis-websocket with Apache License 2.0 4 votes vote down vote up
public ChatWebSocketHandler(DirectProcessor<ChatMessage> messageDirectProcessor, RedisChatMessagePublisher redisChatMessagePublisher, RedisAtomicLong activeUserCounter) {
	this.messageDirectProcessor = messageDirectProcessor;
	this.chatMessageFluxSink = messageDirectProcessor.sink();
	this.redisChatMessagePublisher = redisChatMessagePublisher;
	this.activeUserCounter = activeUserCounter;
}
 
Example #7
Source File: HerokuRedisConfig.java    From spring-redis-websocket with Apache License 2.0 4 votes vote down vote up
@Bean
RedisAtomicLong activeUserCounter(RedisConnectionFactory redisConnectionFactory) {
	return new RedisAtomicLong(ACTIVE_USER_KEY, redisConnectionFactory);
}
 
Example #8
Source File: RedisConfig.java    From spring-redis-websocket with Apache License 2.0 4 votes vote down vote up
@Bean
RedisAtomicLong activeUserCounter(RedisConnectionFactory redisConnectionFactory) {
	return new RedisAtomicLong(ACTIVE_USER_KEY, redisConnectionFactory);
}
 
Example #9
Source File: ReactiveWebSocketConfig.java    From spring-redis-websocket with Apache License 2.0 4 votes vote down vote up
@Bean
public ChatWebSocketHandler webSocketHandler(RedisChatMessagePublisher redisChatMessagePublisher, RedisAtomicLong activeUserCounter) {
	DirectProcessor<ChatMessage> messageDirectProcessor = DirectProcessor.create();
	return new ChatWebSocketHandler(messageDirectProcessor, redisChatMessagePublisher, activeUserCounter);
}
 
Example #10
Source File: RedisChatMessagePublisher.java    From spring-redis-websocket with Apache License 2.0 4 votes vote down vote up
public RedisChatMessagePublisher(ReactiveStringRedisTemplate reactiveStringRedisTemplate, RedisAtomicInteger chatMessageCounter, RedisAtomicLong activeUserCounter, ObjectMapper objectMapper) {
	this.reactiveStringRedisTemplate = reactiveStringRedisTemplate;
	this.chatMessageCounter = chatMessageCounter;
	this.activeUserCounter = activeUserCounter;
	this.objectMapper = objectMapper;
}