Search in sources :

Example 6 with RedisClientMediator

use of com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator in project LinkAgent by shulieTech.

the class LettuceMasterSlaveFactory method getClient.

public Object getClient(Advice advice) {
    if (!GlobalConfig.getInstance().isShadowDbRedisServer()) {
        return advice.getReturnObj();
    }
    if (!doBefore()) {
        return advice.getReturnObj();
    }
    RedisClientMediator mediator = getMediator(advice);
    pressureConnectionCache.put(mediator.getPerformanceRedisClient(), advice.getReturnObj());
    if (mediator == null) {
        // 抛出相关异常信息
        throw new PressureMeasureError(" get redis shadow server error.");
    }
    return security(mediator.getClient());
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) RedisClientMediator(com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator)

Example 7 with RedisClientMediator

use of com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator in project LinkAgent by shulieTech.

the class LettuceMasterSlaveFactory method create.

private RedisClientMediator<?> create(Advice advice) {
    ShadowRedisConfig shadowRedisConfig = serverMatch.getConfig(advice);
    if (null == shadowRedisConfig) {
        ErrorReporter.buildError().setErrorType(ErrorTypeEnum.RedisServer).setErrorCode("redisServer-0001").setMessage("没有配置影子Redis Server").setDetail("没有配置影子Redis Server").report();
        // 抛出相关异常信息
        throw new PressureMeasureError("not found redis shadow server config error.");
    }
    validationConfig(shadowRedisConfig);
    RedisClientMediator mediator = createMediator(advice, shadowRedisConfig);
    putMediator(advice.getReturnObj(), mediator);
    return mediator;
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) ShadowRedisConfig(com.pamirs.pradar.internal.config.ShadowRedisConfig) RedisClientMediator(com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator)

Example 8 with RedisClientMediator

use of com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator in project LinkAgent by shulieTech.

the class JedisFactory method createMediator.

@Override
public RedisClientMediator<JedisPool> createMediator(Object client, ShadowRedisConfig shadowConfig) {
    RedisClientMediator mediator = null;
    String className = client.getClass().getName();
    Object shadowClient = null;
    Integer shadowDb = shadowConfig.getDatabase();
    /**
     * 反射是为了兼容没有getDb的版本
     * 向下转为Integer是为了兼容Long类型的入参
     */
    Integer bizDb = Integer.parseInt(String.valueOf(Reflect.on(Reflect.on(client).get("client")).get("db")));
    String shadowPassword = shadowConfig.getPassword();
    if (JedisConstant.JEDIS.equals(className)) {
        // 单节点
        String nodes = shadowConfig.getNodes();
        if (!nodes.contains(":")) {
            shadowClient = new Jedis(nodes);
        } else {
            String[] splitter = nodes.split(":");
            shadowClient = new Jedis(splitter[0], Integer.valueOf(splitter[1]));
        }
        if (!StringUtil.isEmpty(shadowPassword)) {
            ((Jedis) shadowClient).auth(shadowPassword);
        }
        if (shadowDb != null) {
            ((Jedis) shadowClient).select(shadowDb);
        } else {
            // 用业务的db
            ((Jedis) shadowClient).select(bizDb);
        }
    } else if (JedisConstant.BINARY_JEDIS.equals(className)) {
        String nodes = shadowConfig.getNodes();
        if (!nodes.contains(":")) {
            shadowClient = new Jedis(nodes);
        } else {
            String[] splitter = nodes.split(":");
            shadowClient = new BinaryJedis(splitter[0], Integer.valueOf(splitter[1]));
        }
        if (shadowDb != null) {
            ((BinaryJedis) shadowClient).select(shadowDb);
        } else {
            // 用业务的db
            ((BinaryJedis) shadowClient).select(bizDb);
        }
        if (!StringUtil.isEmpty(shadowPassword)) {
            ((BinaryJedis) shadowClient).auth(shadowPassword);
        }
    }
    mediator = new RedisClientMediator(client, shadowClient);
    return mediator;
}
Also used : BinaryJedis(redis.clients.jedis.BinaryJedis) BinaryJedis(redis.clients.jedis.BinaryJedis) Jedis(redis.clients.jedis.Jedis) RedisClientMediator(com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator)

Aggregations

RedisClientMediator (com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator)8 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)2 ShadowRedisConfig (com.pamirs.pradar.internal.config.ShadowRedisConfig)2 RedissonReactiveClient (org.redisson.api.RedissonReactiveClient)2 AbstractRedisClient (io.lettuce.core.AbstractRedisClient)1 RedisClient (io.lettuce.core.RedisClient)1 RedisURI (io.lettuce.core.RedisURI)1 RedisClusterClient (io.lettuce.core.cluster.RedisClusterClient)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)1 RedissonClient (org.redisson.api.RedissonClient)1 ClusterServersConfig (org.redisson.config.ClusterServersConfig)1 Config (org.redisson.config.Config)1 MasterSlaveServersConfig (org.redisson.config.MasterSlaveServersConfig)1 ReplicatedServersConfig (org.redisson.config.ReplicatedServersConfig)1 SentinelServersConfig (org.redisson.config.SentinelServersConfig)1 SingleServerConfig (org.redisson.config.SingleServerConfig)1 BinaryJedis (redis.clients.jedis.BinaryJedis)1