All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alicp.jetcache.autoconfigure.JedisPoolFactory Maven / Gradle / Ivy

The newest version!
package com.alicp.jetcache.autoconfigure;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.util.Pool;

/**
 * Created on 2016/12/28.
 *
 * @author huangli
 */
public class JedisPoolFactory implements FactoryBean> {
    private String key;
    private Class poolClass;

    @Autowired
    private AutoConfigureBeans autoConfigureBeans;

    private boolean inited;
    private Pool jedisPool;

    public JedisPoolFactory(String key, Class> poolClass){
        this.key = key;
        this.poolClass = poolClass;
    }

    public String getKey() {
        return key;
    }

    @Override
    public Pool getObject() throws Exception {
        if (!inited) {
            jedisPool = (Pool) autoConfigureBeans.getCustomContainer().get("jedisPool." + key);
            inited = true;
        }
        return jedisPool;
    }

    @Override
    public Class getObjectType() {
        return poolClass;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy