You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

51 lines
1.4 KiB

  1. package com.simple.config;
  2. import org.apache.log4j.Logger;
  3. import org.springframework.beans.factory.annotation.Value;
  4. import org.springframework.cache.annotation.CachingConfigurerSupport;
  5. import org.springframework.cache.annotation.EnableCaching;
  6. import org.springframework.context.annotation.Bean;
  7. import org.springframework.context.annotation.Configuration;
  8. import redis.clients.jedis.JedisPool;
  9. import redis.clients.jedis.JedisPoolConfig;
  10. /**
  11. * Created by yangqj on 2017/4/30.
  12. */
  13. @Configuration
  14. @EnableCaching
  15. public class RedisConfig extends CachingConfigurerSupport {
  16. @Value("${spring.redis.host}")
  17. private String host;
  18. @Value("${spring.redis.port}")
  19. private int port;
  20. @Value("${spring.redis.timeout}")
  21. private int timeout;
  22. @Value("${spring.redis.pool.max-idle}")
  23. private int maxIdle;
  24. @Value("${spring.redis.pool.max-wait}")
  25. private long maxWaitMillis;
  26. @Value("${spring.redis.password}")
  27. private String password;
  28. @Bean
  29. public JedisPool redisPoolFactory() {
  30. Logger.getLogger(getClass()).info("JedisPool注入成功!!");
  31. Logger.getLogger(getClass()).info("redis地址:" + host + ":" + port);
  32. JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
  33. jedisPoolConfig.setMaxIdle(maxIdle);
  34. jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
  35. JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout,password);
  36. return jedisPool;
  37. }
  38. }