Jedis配置,项目启动注入JedisPool

Jedis配置,项目启动注入JedisPoolJedis配置,项目启动注入JedisPool@EnableAutoConfiguration@PropertySource(“classpath:config.properties”)@ConfigurationProperties(prefix=”redis”)publicclassJedisConfig{/***LOGGER*/…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

Jedis配置,项目启动注入JedisPool

@EnableAutoConfiguration
@PropertySource("classpath:config.properties")
@ConfigurationProperties(prefix = "redis")
public class JedisConfig {
    /**
     * LOGGER
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(JedisConfig.class);
    private String host;
    private int port;
    private String password;
    private int timeout;
    @Value("${redis.pool.max-active}")
    private int maxActive;
    @Value("${redis.pool.max-wait}")
    private int maxWait;
    @Value("${redis.pool.max-idle}")
    private int maxIdle;
    @Value("${redis.pool.min-idle}")
    private int minIdle;
    @Bean
    public JedisPool redisPoolFactory() {
        try {
            JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
            jedisPoolConfig.setMaxIdle(maxIdle);
            jedisPoolConfig.setMaxWaitMillis(maxWait);
            jedisPoolConfig.setMaxTotal(maxActive);
            jedisPoolConfig.setMinIdle(minIdle);
            // JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password);
            JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, null);
            LOGGER.info("初始化Redis连接池JedisPool成功!地址: " + host + ":" + port);
            return jedisPool;
        } catch (Exception e) {
            LOGGER.error("初始化Redis连接池JedisPool异常:" + e.getMessage());
        }
        return null;
    }
    public String getHost() {
        return host;
    }
    public void setHost(String host) {
        this.host = host;
    }
    public int getPort() {
        return port;
    }
    public void setPort(int port) {
        this.port = port;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public int getTimeout() {
        return timeout;
    }
    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }
    public int getMaxActive() {
        return maxActive;
    }
    public void setMaxActive(int maxActive) {
        this.maxActive = maxActive;
    }
    public int getMaxWait() {
        return maxWait;
    }
    public void setMaxWait(int maxWait) {
        this.maxWait = maxWait;
    }
    public int getMaxIdle() {
        return maxIdle;
    }
    public void setMaxIdle(int maxIdle) {
        this.maxIdle = maxIdle;
    }
    public int getMinIdle() {
        return minIdle;
    }
    public void setMinIdle(int minIdle) {
        this.minIdle = minIdle;
    }
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/197876.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • swoole 建立httpserver 服务[通俗易懂]

    swoole 建立httpserver 服务

    2022年2月12日
    38
  • 区块链P2P网络协议演进过程[通俗易懂]

    区块链P2P网络协议演进过程[通俗易懂]区块链是以加密机制、储存机制、共识机制等多种技术组成的分布式系统,可以在无中心服务器的情况下实现相互信任的点对点交易功能。区块链最大的特点是去中心化和分布式,区块链共识机制使得参与节点共同为系统提供服务,实现中心化系统中类似金融中介机构的功能。共识机制是网络大部分节点在约定时间段内对交易状态达成相同的确认,其中共识性通过工作量证明(POW)、权益证明(POS)、实用拜占庭容错(PBFT)等多种共识算法实现。而一致性则要求大部分节点在约定时间段内保持数据内容一致,从而利用共识算法实现共识。传统中心化网络系统需

    2022年10月8日
    4
  • Servlet主要知识点

    Servlet主要知识点

    2021年10月3日
    37
  • Binary Tree Postorder Traversal — LeetCode

    Binary Tree Postorder Traversal — LeetCode原题链接: http://oj.leetcode.com/problems/binary-tree-postorder-traversal/ 跟BinaryTreeInorderTraversal以及BinaryTreePreorderTraversal一样,二叉树的后序遍历我们还是介绍三种方法,第一种是递归,第二种是迭代方法,第三种是用线索二叉树。递归还是那么简单,算法

    2025年6月28日
    2
  • Python字符串总结大全

    Python字符串总结大全目录操作符标准类型操作符对象值的比较布尔类型序列操作符切片([]和[:])成员操作符(in,notin)连接符(+)运行时刻字符串连接编译时字符串连接普通字符串转化为Unicode字符串重复操作符(*)只适用于字符串的操作符格式化操作符(%)字符串模板:更简单的替代品原始字符串操作符(r/R)Unicode字符串操作符(u/U)常见的转义字符字符串索引编解码内建函数序列类型函数len()max()和min()en

    2022年6月9日
    31
  • windows10 Linux子系统(wsl)文件目录

    windows10 Linux子系统(wsl)文件目录简介使用window中的Linux子系统创建的文件究竟放在什么地方,既然作为子系统文件肯定是可以互相访问的目录ubuntuLinux子系统的目录是在这个目录下C:\Users\用户名\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs现在在…

    2022年6月3日
    910

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号