springboot整合redis

复制代码
spring:
  redis:
    port: 6379
    host: 192.168.88.101
    password: 111111
    lettuce:
      pool:
        max-active: 8
        max-wait: -1ms
    database: 0
复制代码

yml配置(单机版)

复制代码
spring:
  redis:
    password: 111111
    lettuce:
      cluster:
        refresh:
          adaptive: true
          period: 2000
    cluster:
      max-redirects: 3
      nodes: ip:port,ip:port,ip:port,ip:port,ip:port,ip:port
复制代码

yml配置(集群版),同时支持集群拓扑动态感应刷新

复制代码
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-redis</artifactId>
      <version>2.7.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-pool2</artifactId>
      <version>2.11.1</version>
    </dependency>
复制代码

相关依赖

复制代码
    @Autowired
    private StringRedisTemplate redisTemplate;
    //这里我使用的是stringredistemplate而不是redistemplate,主要是我懒得写那个配置类了。。。
    public void add(String key,String value){
        redisTemplate.opsForValue().set(key,value);
    }

    public String getById(Integer id){
        return redisTemplate.opsForValue().get(ORDER_KEY+id);
    }
复制代码

service层实现

posted @   天启A  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
点击右上角即可分享
微信分享提示