zoukankan      html  css  js  c++  java
  • redis20

    需知  

      目前 java 操作 redis 的客户端有jedis Lettuce

      在 springboot1.x 系列中,使用的是 jedis

      到了 springboot2.x 系列使用的是 Lettuce

      目前我们线上开发基本上都使用的版本是 springboot2.x 系列,所以我们需要会使用 Lettuce

      关于 jedis lettuce 的区别在 redis19 章节已经聊过了,这里就不做冗余阐述了。

    实现步骤

     1、添加 pom 依赖

    <!--springboot中的redis依赖-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>
    <!-- lettuce pool 缓存连接池-->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-pool2</artifactId>
    </dependency>

      注意点:使用pool,那么必须在 pom.xml 添加上 commons-pool2 的依赖。没配置 pool 的话,可以不引用。

     2、配置 redis.properties,其中如下:

    spring.redis.host=127.0.0.1
    spring.redis.port=6379
    #连接池最大链接数默认值为8
    spring.redis.lettuce.pool.max-active=8
    #连接池最大阻塞时间(使用负值表示没有限制)默认为-1
    spring.redis.lettuce.pool.max-wait=-1
    #连接池中的最大空闲连接数 默认为8
    spring.redis.lettuce.pool.max-idle=8
    #连接池中的最小空闲连接数 默认为8
    spring.redis.lettuce.pool.min-idle=0
  • 相关阅读:
    C++ STL 介绍
    C++多线程学习笔记 (CreateThread()与 _beginthreadex() )
    Spring轻量级开发---基础知识和初体验
    J2EE面试题
    SSH的优缺点比较
    Qt容器类总结
    Qt Creater使用技巧
    Visual Studio里使用Qt
    Qt的学习之路
    解决Github下载慢和下载失败问题
  • 原文地址:https://www.cnblogs.com/liang1101/p/13507156.html
Copyright © 2011-2022 走看看