赞
踩
一、在pom.xml文件中添加Jedis的依赖
- <!--集成Redis-->
-
- <dependency>
- <groupId>redis.clients</groupId>
- <artifactId>jedis</artifactId>
- <version>2.9.0</version>
- </dependency>
二、springboot配置文件application.properties中的redis配置
- #Redis
- redis.DB=6
- redis.host=127.0.0.1
- redis.port=6380
- redis.password=
- redis.timeout=10000
- redis.max-active=200
- redis.max-idle=10
- redis.min-idle=10
- redis.max-wait=10000
三、创建一个生成JedisPool的工厂,注意加上@Configuration注解,否则jedisPool为空,
- package com.niucheng.eblog.common.redis;
-
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import redis.clients.jedis.JedisPool;
- import redis.clients.jedis.JedisPoolConfig;
-
- /**
- * 创建一个生成JedisPool的工厂
- */
- @Configuration
- public class JedisPoolFactory {
-
- @Value("${redis.host}")
- private String host;
-
- @Value("${redis.port}")
- private int port;
-
- @Value("${redis.password}")
- private String password;
-
- @Value("${redis.timeout}")
- private int timeout;
-
- @Value("${redis.max-active}")
- private int maxActive;
-
- @Value("${redis.max-idle}")
- private int maxIdle;
-
- @Value("${redis.min-idle}")
- private int minIdle;
-
- @Value("${redis.max-wait}")
- private long maxWaitMillis;
-
-
- @Bean
- public JedisPool generateJedisPoolFactory() {
- JedisPoolConfig poolConfig = new JedisPoolConfig();
- poolConfig.setMaxTotal(maxActive);
- poolConfig.setMaxIdle(maxIdle);
- poolConfig.setMinIdle(minIdle);
- poolConfig.setMaxWaitMillis(maxWaitMillis);
- //指定第6个库
- JedisPool jedisPool = new JedisPool(poolConfig, host, port, timeout, password, 6);
- return jedisP
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。