zoukankan      html  css  js  c++  java
  • Springboot整合redis步骤

    一、加入依赖


    		<dependency>
    			<groupId>com.github.spt-oss</groupId>
    			<artifactId>spring-boot-starter-data-redis</artifactId>
    			<version>2.0.7.0</version>
    		</dependency>
    redis依赖

    二、添加redis.properties配置文件

    # REDIS (RedisProperties)
    # Redis数据库索引(默认为0)
    spring.redis.database=0
    # Redis服务器地址
    spring.redis.host=127.0.0.1
    # Redis服务器连接端口
    spring.redis.port=6379
    # Redis服务器连接密码(默认为空)
    spring.redis.password=123456
    # 连接池最大连接数(使用负值表示没有限制)
    spring.redis.pool.max-active=8
    # 连接池最大阻塞等待时间(使用负值表示没有限制)
    spring.redis.pool.max-wait=-1
    # 连接池中的最大空闲连接
    spring.redis.pool.max-idle=8
    # 连接池中的最小空闲连接
    spring.redis.pool.min-idle=0
    # 连接超时时间(毫秒)
    #加了连接池可以不用设置
    spring.redis.timeout=2000ms
    redis配置文件

    三、加载redis.properties配置文件

    在@SpringBootApplication注解的类上加上

    @PropertySource({ "classpath:redis.properties" })

    四、获取操作对象

    获取redis操作对象

    @Autowired
    private RedisTemplate<String, String> redisTemplate;
  • 相关阅读:
    移动服务
    CodeForces
    poj1737-----这题有毒
    洛谷P1219 八皇后 (dfs+回溯法)
    codeforces 598D Igor In the Museum(dfs)
    CCPC-Wannafly & Comet OJ 夏季欢乐赛(2019)I
    复制构造函数的作用
    codeforces 1102D Balanced Ternary String(贪心+思维)
    学习3DES加密算法笔记
    个人冲刺(六)
  • 原文地址:https://www.cnblogs.com/mowen120/p/11953707.html
Copyright © 2011-2022 走看看