SpringBoot整合redis


1.导入依赖

  
            org.springframework.boot
            spring-boot-starter-data-redis
  

2.配置连接

spring.redis.host=    ip地址
spring.redis.port= 6379

3.测试

@SpringBootTest
class Redis02SpringbootApplicationTests {

    @Resource
    private RedisTemplate redisTemplate;

    @Test
    void contextLoads() {

        //opsForValue 操作字符串 类似String
        //opsForList  操作list  类似List
        //opsForHash
        //opsForSet
        //opsForZSet
        //opsForGeo
        //opsForHyperLogLog


         //获取redis的连接对象
//        RedisConnection connection = redisTemplate.getConnectionFactory().getConnection();
//        connection.flushDb();
//        connection.flushAll();


         redisTemplate.opsForValue().set("mykey","redis");
        Object mykey = redisTemplate.opsForValue().get("mykey");
        System.out.println(mykey);


    }