缓存:redis测试


    <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-data-redisartifactId>
        dependency>

配置:

  redis:
    host: 192.168.155.3

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Test
    public void testStringRedisTemplate(){
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        //保存
        ops.set("hello","world_"+ UUID.randomUUID().toString());

        //查询
        String s = ops.get("hello");
        System.out.println("s = " + s);
        
    }

 redis中查看:

默认是0号数据库。

原来redis操作这么简单,之前看另一个老师讲的,都搞复杂了。。