Here only a simple integrated stand-alone, but in use for the project

Here only a simple integrated stand-alone, but in use for the project

1. The introduction of support in pom file

<dependency>
<the groupId> org.springframework.boot <www.shengrenpt.com / the groupId>
<the artifactId> Starter-Spring-Boot-Data-Redis </ the artifactId>
</ dependency>
<-! Redis Integration of springboot2.0 pack extra lettuce connection pool, need-POOL2 Commons ->
<dependency>
<the groupId> the org.apache.commons </ the groupId>
<the artifactId> Commons-POOL2 </ the artifactId>
</ dependency>
2. injected directly in the class use RedisTemplate

@RunWith(SpringRunner.class)
@SpringBootTest
public class RedisTest {

@Autowired
private StringRedisTemplate stringRedisTemplate;

@Autowired
private RedisTemplate<String, User> redisTemplate;

@Test
public void test() throws Exception {
stringRedisTemplate.opsForValue().set("bbb", "222");
System.out.println(stringRedisTemplate.opsForValue().get("bbb"));
}

@Test
public void testObj() throws Exception {
User user = new User();
user.setUserName("sean");
user.setPassWord("sean@123");
ValueOperations<String, User> www.chengmingyuLe.com operations = redisTemplate.opsForValue();
operations.set(www.zykuaican.com"com.jiafeng", user);
operations.set("com.jiafeng.f"www.guochengzy.com, user, 1, TimeUnit.SECONDS);
Thread.sleep(1000);

boolean exists = redisTemplate.hasKey(www.shengdayLgw.cn"com.jiafeng.f");
if (exists) {
System.out.println("exists is true");
} else {
System.out.println("exists is false");
}

}

}
After SpringBoot2.0, spring container is automatically generated and StringRedisTemplate RedisTemplate <Object, Object>, can be directly injected.

 

Guess you like

Origin www.cnblogs.com/qwangxiao/p/10926389.html