028-86922220

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

SpringBoot集成Redis操作API的方法

这篇文章主要介绍“SpringBoot集成redis操作API的方法”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“SpringBoot集成Redis操作API的方法”文章能帮助大家解决问题。

创新互联是专业的汝州网站建设公司,汝州接单;提供做网站、成都做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行汝州网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

SpringDataRedis调用Redis底层解读

SpringBoot整合Redis(源码分析)

SpringBoot整合Redis(配置)

yml

spring:
  redis:
    host: localhost
    port: 6379

Maven

在项目创建的时候选择,如果没有选择就添加

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

编写测试

redisTemplate.unwatch();
redisTemplate.watch("key");
redisTemplate.multi();
redisTemplate.discard();
redisTemplate.exec();

关于数据库的操作需要获取链接后使用连接对象操作

RedisConnection connection = redisTemplate.getConnectionFactory().getConnection();connection.flushAll();connection.flushDb();connection.close();

测试代码及其执行结果

package co.flower.redis02springboot;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.RedisConnection;import org.springframework.data.redis.core.RedisTemplate;

@SpringBootTestclass Redis02SpringbootApplicationTests {/** * 我居然直接就指定了泛型 RedisTemplate结果就直接报错了,删除泛型后成功     */@Autowiredprivate RedisTemplate redisTemplate;

    @Testvoid contextLoads() {// 英文测试redisTemplate.opsForValue().set("name","xiaojiejie");
        System.out.println(redisTemplate.opsForValue().get("name"));// 中文测试redisTemplate.opsForValue().set("name","小姐姐");
        System.out.println(redisTemplate.opsForValue().get("name"));
    }

}

执行结果,SpringBoot的启动加载和结束销毁没有粘贴/***SpringBootStart****/xiaojiejie
小姐姐/***SpringBootStop*****/

关于“SpringBoot集成Redis操作API的方法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注创新互联行业资讯频道,小编每天都会为大家更新不同的知识点。


新闻名称:SpringBoot集成Redis操作API的方法
URL标题:http://www.tsicrk.com/article/gdopij.html

其他资讯

让你的专属顾问为你服务

3.0112s