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());
}
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;
}
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;
}
Aggregations