用redis为spring data jpa创建唯一id
@Service
public class IDServiceImpl implements IDService {
@Resource
private RedisTemplate<String, Serializable> redisTemplate;
@Override
public long generate(String key) {
RedisAtomicLong counter = new RedisAtomicLong(key,
Objects.requireNonNull(redisTemplate.getConnectionFactory()));
return counter.incrementAndGet();
}
}
使用redis的事务机制来创建并发情况下的唯一id