50,530
社区成员
发帖
与我相关
我的任务
分享
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
package com.atguigu.rabbitmq;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
/**
* Create by PC6 2020/2/27
*/
@SpringBootTest
public class TestCRedis {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
private RedisTemplate redisTemplate;
@Test
public void t2() {
for (int i = 0; i <= 2; i++) {
LettuceConnectionFactory connectionFactory = (LettuceConnectionFactory) this.stringRedisTemplate
.getConnectionFactory();
connectionFactory.setDatabase(i);
this.stringRedisTemplate.setConnectionFactory(connectionFactory);
connectionFactory.resetConnection();
ValueOperations valueOperations = this.stringRedisTemplate.opsForValue();
valueOperations.set("test" + i, "TEST" + i);
String test = (String) valueOperations.get("test" + i);
System.out.println("test:" + test);
}
}
}