zoukankan      html  css  js  c++  java
  • 阿里P7级教你如何在Spring Boot应用程序中使用Redis

    在Spring Boot应用程序中使用Redis缓存的步骤:

    1、要获得Redis连接,我们可以使用Lettuce或Jedis客户端库,Spring Boot 2.0启动程序spring-boot-starter-data-redis默认使用了Lettuce。要获得Redis的池化连接工厂,我们需要在类路径上提供commons-pool2,下面展示使用Lettuce情况下的Maven依赖项配置:

    org.springframework.bootspring-boot-starter-data-redisorg.apache.commonscommons-pool2

    2、在application.properties中配置spring.redis.*前缀的参数:

    spring.redis.host=localhost
    spring.redis.port=6379
    spring.redis.password=
    spring.redis.lettuce.pool.max-active=7
    spring.redis.lettuce.pool.max-idle=7
    spring.redis.lettuce.pool.min-idle=2
    spring.redis.lettuce.pool.max-wait=-1ms
    spring.redis.lettuce.shutdown-timeout=200ms
    spring.cache.redis.cache-null-values=false
    spring.cache.redis.time-to-live=600000
    spring.cache.redis.use-key-prefix=true

    3、在 @SpringBootApplication类使用@EnableCaching激活Redis:

    @SpringBootApplication
    @EnableCaching
    publicclassSpringBootAppStarter {
    publicstaticvoidmain(String[] args) {
    SpringApplication.run(SpringBootAppStarter.class, args);
    }
    }

    如果想用Jedis 客户端,需要排除Lettuce,加入Jedis:

    org.springframework.bootspring-boot-starter-data-redisio.lettucelettuce-coreredis.clientsjedis

    jedis将自动在类路径上解决commons-pool2, application配置:

    spring.redis.host=localhost 
    spring.redis.port=6379
    spring.redis.password= spring.redis.jedis.pool.max-active=7
    spring.redis.jedis.pool.max-idle=7
    spring.redis.jedis.pool.min-idle=2
    spring.redis.jedis.pool.max-wait=-1ms

     

    写在最后:欢迎留言讨论,加关注,持续更新!!!

  • 相关阅读:
    飞机游戏
    nodejs制作爬虫程序
    关于解析字符串
    引用nodejs的url模块实现url路由功能
    appium定位学习
    appium移动端自动化测试的一些感想
    appium的工作原理
    appium desktop 定位弹出框时报错
    APPium连接真机输入框中输入的内容与代码中不一致
    appium 链接真机后,运行代码,但是APP并没有启动
  • 原文地址:https://www.cnblogs.com/Ti1077/p/9626833.html
Copyright © 2011-2022 走看看