public interface IJedisClientFactory {
    Jedis getJedis();
}
JedisClientFactoryImpl.java
@Service
public class JedisClientFactoryImpl implements IJedisClientFactory {
    private final JedisPool pool;
    private final String password;

    public JedisClientFactoryImpl() {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setBlockWhenExhausted(false);
        config.setMaxTotal(150);
        config.setMaxIdle(150);
        config.setMinIdle(100);
        config.setMaxWaitMillis(2000);
        config.setMinEvictableIdleTimeMillis(300000);
        config.setTestOnBorrow(false);
        InputStream inputStream = this.getClass().getResourceAsStream("/jedis.properties");
        Properties properties = new Properties();
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String url = (String)properties.get("url");
        int port = Integer.parseInt((String)properties.get("port"));
        int timeout = Integer.parseInt((String)properties.get("timeout"));
        password = (String)properties.get("password");

        pool = new JedisPool(config, url,port,timeout);
    }

    @Override
    public synchronized Jedis  getJedis() {
        Jedis resource = pool.getResource();
        resource.auth(password);
        return resource;
    }

    @PreDestroy
    public void closePool(){
        pool.destroy();
    }
}

最新文章

  1. javascript中针对float的ceil及floor
  2. Codeforces CF#628 Education 8 E. Zbazi in Zeydabad
  3. eclipse js卡顿
  4. python常用代码
  5. div图片垂直居中 如何使div中图片垂直居中
  6. python爬虫下载youtube单个视频
  7. 如何实现在O(n)时间内排序,并且空间复杂度为O(1)
  8. No orientation specified, and the default is
  9. Spring Boot 系列教程12-EasyPoi导出Excel下载
  10. javascript 计算两个日期的差值
  11. ES6的generator函数
  12. JQuery其他常用函数
  13. BAT面试官告诉你如何回答你的职业规划
  14. Nagios故障 CHECK_NRPE: Socket timeout after 10 seconds.
  15. SpringCloud第一弹(入门)
  16. Win10更新搜狗输入法后重启输入密码蓝屏
  17. BZOJ 2457 - 双端队列 - [思维题]
  18. META标签之关键词、网页描述设置帮助SEO网站优化(转)
  19. kt 集合
  20. Messages: java.lang.NullPointerExceptionFile: org/apache/jsp/test_jsp.javaLine number: 23

热门文章

  1. nginx location匹配顺序及CI框架的nginx配置
  2. PHP实现KMP算法
  3. ConcurrentHashMap源码解析(JDK1.8)
  4. 分享基于Qt5开发的一款故障波形模拟软件
  5. poj-1012-约瑟夫问题
  6. C++模板入门教程(一)——模板概念与基本语法
  7. ArrayList 源码分析
  8. c++ --> sizeof()使用小结
  9. 测试驱动开发实践3————testSave之新增用户
  10. NVL2 这个函数,