完成springboot-redis升级
This commit is contained in:
@ -34,6 +34,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
@ -54,6 +58,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.vaadin.external.google</groupId>
|
||||
|
||||
@ -7,11 +7,13 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class UserService {
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
@Resource
|
||||
|
||||
@ -7,9 +7,9 @@ spring:
|
||||
profiles:
|
||||
active: dev
|
||||
datasource:
|
||||
url: jdbc:mysql://127.0.0.1:3306/test?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
|
||||
url: jdbc:mysql://123.207.66.156:3306/test?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
|
||||
username: root
|
||||
password: 123456
|
||||
password: _EnZhi123
|
||||
|
||||
################### mybatis-plus配置 ###################
|
||||
mybatis-plus:
|
||||
@ -39,16 +39,22 @@ spring:
|
||||
profiles: dev
|
||||
cache:
|
||||
type: REDIS
|
||||
redis:
|
||||
cache-null-values: false
|
||||
time-to-live: 600000ms
|
||||
use-key-prefix: true
|
||||
cache-names: userCache,allUsersCache
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
host: 123.207.66.156
|
||||
port: 6379
|
||||
timeout: 0
|
||||
database: 0
|
||||
pool:
|
||||
max-active: 100
|
||||
max-wait: -1
|
||||
max-idle: 8
|
||||
min-idle: 0
|
||||
lettuce:
|
||||
shutdown-timeout: 200ms
|
||||
pool:
|
||||
max-active: 7
|
||||
max-idle: 7
|
||||
min-idle: 2
|
||||
max-wait: -1ms
|
||||
|
||||
logging:
|
||||
level:
|
||||
|
||||
@ -8,6 +8,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@ -24,12 +25,13 @@ import static org.junit.Assert.assertNull;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
@Transactional
|
||||
public class UserServiceTest {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Test
|
||||
public void testCache() {
|
||||
int id = new Random().nextInt(100);
|
||||
int id = new Random().nextInt(1000);
|
||||
User user = new User(id, "admin", "admin");
|
||||
userService.createUser(user);
|
||||
User user1 = userService.getById(id); // 第1次访问
|
||||
|
||||
Reference in New Issue
Block a user