Search in sources :

Example 1 with Client

use of redis.clients.jedis.Client in project LinkAgent by shulieTech.

the class JedisNodesStrategy method match.

/**
 * obj是redis.clients.jedis.Jedis或者redis.clients.jedis.BinaryJedis
 *
 * @param obj 任意对象
 * @return
 */
@Override
public List<String> match(Object obj) {
    if (!BinaryJedis.class.isAssignableFrom(obj.getClass())) {
        LOGGER.info("not support type of jedis single mode , class is not" + " redis.clients.jedis.Jedis or redis.clients.jedis.BinaryJedis");
        return new ArrayList<String>();
    }
    List<String> nodes = new ArrayList<String>();
    try {
        Reflect reflect = Reflect.on(obj);
        Client client = reflect.get("client");
        Reflect clientRef = Reflect.on(client);
        String password = clientRef.get("password");
        String host = clientRef.get("host");
        String port = String.valueOf(clientRef.get("port"));
        String db = String.valueOf(clientRef.get("db"));
        nodes.add(getKey(host, port));
    } catch (Throwable e) {
        LOGGER.error("", e);
    }
    return nodes;
}
Also used : BinaryJedis(redis.clients.jedis.BinaryJedis) Reflect(com.shulie.instrument.simulator.api.reflect.Reflect) ArrayList(java.util.ArrayList) Client(redis.clients.jedis.Client)

Example 2 with Client

use of redis.clients.jedis.Client in project LinkAgent by shulieTech.

the class Model method isSingleMode.

/**
 * 是否单节点模式
 *
 * @param jedis
 * @return
 */
public boolean isSingleMode(Object jedis) {
    if (isSentinelMode(jedis)) {
        return false;
    }
    Client client = Reflect.on(jedis).get("client");
    String host = client.getHost();
    String port = String.valueOf(client.getPort());
    String node = host.concat(":").concat(String.valueOf(port));
    return !clusterNoCache.contains(node) && !pressureNotSingleModelCache.contains(node);
}
Also used : Client(redis.clients.jedis.Client)

Example 3 with Client

use of redis.clients.jedis.Client in project LinkAgent by shulieTech.

the class RedisUtils method jedisServiceName.

/**
 * 服务端可能是 redis、codis、pika
 * 客户端链接工具用的是 jedis
 */
public static String jedisServiceName(BinaryJedis binaryJedis) {
    Client client = binaryJedis.getClient();
    // get from cache
    String cacheKey = remoteIpStr(client.getHost(), client.getPort());
    String serviceName = HOST_SERVER_TYPE_MAP.get(cacheKey);
    if (serviceName != null) {
        return serviceName;
    }
    String info;
    try {
        info = binaryJedis.info();
    } catch (Throwable throwable) {
        // 如果 redis 读客户的 info 接口报错,那么就直接用默认的名称
        return defaultServiceStr(cacheKey);
    }
    if (info == null || info.length() == 0) {
        // 读不到 redis 服务器上面的信息
        return defaultServiceStr(cacheKey);
    }
    String[] props = StringUtils.split(info, "\r\n");
    if (props.length == 0) {
        // redis 服务器上面的信息为空
        return defaultServiceStr(cacheKey);
    }
    for (String prop : props) {
        if (prop.startsWith("#")) {
            // this is comment
            continue;
        }
        if (prop.startsWith("redis_version")) {
            HOST_SERVER_TYPE_MAP.put(cacheKey, REDIS_SERVER_REDIS);
            return REDIS_SERVER_REDIS;
        }
        if (prop.startsWith("pika_version")) {
            HOST_SERVER_TYPE_MAP.put(cacheKey, REDIS_SERVER_PIKA);
            return REDIS_SERVER_PIKA;
        }
    // other server be add
    }
    return defaultServiceStr(cacheKey);
}
Also used : Client(redis.clients.jedis.Client)

Example 4 with Client

use of redis.clients.jedis.Client in project skywalking-java by apache.

the class TransactionConstructorInterceptorTest method onConstruct.

@Test
public void onConstruct() throws Throwable {
    interceptor.onConstruct(enhancedInstance, new Object[] { new Client("127.0.0.1", 6379) });
    verify(enhancedInstance).setSkyWalkingDynamicField("127.0.0.1:6379");
}
Also used : Client(redis.clients.jedis.Client) Test(org.junit.Test)

Example 5 with Client

use of redis.clients.jedis.Client in project skywalking-java by apache.

the class PipelineSetClientMethodInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    Client client = (Client) allArguments[0];
    objInst.setSkyWalkingDynamicField(client.getHost() + ":" + client.getPort());
}
Also used : Client(redis.clients.jedis.Client)

Aggregations

Client (redis.clients.jedis.Client)16 Jedis (redis.clients.jedis.Jedis)4 Reflect (com.shulie.instrument.simulator.api.reflect.Reflect)2 BinaryJedis (redis.clients.jedis.BinaryJedis)2 ClientInfo (com.cdeledu.util.database.redis.entity.ClientInfo)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ITraceSpan (org.bithon.agent.core.tracing.context.ITraceSpan)1 Before (org.junit.Before)1 Test (org.junit.Test)1 JedisMovedDataException (redis.clients.jedis.exceptions.JedisMovedDataException)1 JedisRedirectionException (redis.clients.jedis.exceptions.JedisRedirectionException)1