Search in sources :

Example 6 with JedisConnectionException

use of redis.clients.jedis.exceptions.JedisConnectionException in project cachecloud by sohutv.

the class Connection method disconnect.

public void disconnect() {
    if (isConnected()) {
        try {
            outputStream.flush();
            socket.close();
        } catch (IOException ex) {
            UsefulDataCollector.collectException(ex, getHostPort(), System.currentTimeMillis());
            broken = true;
            throw new JedisConnectionException(ex);
        } finally {
            IOUtils.closeQuietly(socket);
        }
    }
}
Also used : IOException(java.io.IOException) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException)

Example 7 with JedisConnectionException

use of redis.clients.jedis.exceptions.JedisConnectionException in project cachecloud by sohutv.

the class Connection method readProtocolWithCheckingBroken.

protected Object readProtocolWithCheckingBroken() {
    Object o = null;
    try {
        o = Protocol.read(inputStream);
        return o;
    } catch (JedisConnectionException exc) {
        UsefulDataCollector.collectException(exc, getHostPort(), System.currentTimeMillis());
        broken = true;
        throw exc;
    } finally {
        UsefulDataModel costModel = UsefulDataModel.getCostModel(threadLocal);
        costModel.setHostPort(getHostPort());
        costModel.setEndTime(System.currentTimeMillis());
        // 1.上报command + cost给指定
        if (o != null) {
            if (o instanceof byte[]) {
                byte[] bytes = (byte[]) o;
                // 2.上报字节大小
                costModel.setValueBytesLength(bytes.length);
            }
        }
        // 清除threadLocal
        threadLocal.remove();
        // 排除掉subscribe问题
        if (costModel.getCommand() != null) {
            UsefulDataCollector.collectCostAndValueDistribute(costModel);
        }
    }
}
Also used : UsefulDataModel(com.sohu.tv.jedis.stat.model.UsefulDataModel) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException)

Example 8 with JedisConnectionException

use of redis.clients.jedis.exceptions.JedisConnectionException in project cachecloud by sohutv.

the class Protocol method sendCommand.

private static void sendCommand(final RedisOutputStream os, final byte[] command, final byte[]... args) {
    try {
        os.write(ASTERISK_BYTE);
        os.writeIntCrLf(args.length + 1);
        os.write(DOLLAR_BYTE);
        os.writeIntCrLf(command.length);
        os.write(command);
        os.writeCrLf();
        for (final byte[] arg : args) {
            os.write(DOLLAR_BYTE);
            os.writeIntCrLf(arg.length);
            os.write(arg);
            os.writeCrLf();
        }
    } catch (IOException e) {
        throw new JedisConnectionException(e);
    }
}
Also used : IOException(java.io.IOException) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException)

Example 9 with JedisConnectionException

use of redis.clients.jedis.exceptions.JedisConnectionException in project cachecloud by sohutv.

the class JedisSentinelPoolTest method returnResourceShouldResetState.

@Test
public void returnResourceShouldResetState() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(1);
    config.setBlockWhenExhausted(false);
    JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000, "foobared", 2);
    Jedis jedis = pool.getResource();
    Jedis jedis2 = null;
    try {
        jedis.set("hello", "jedis");
        Transaction t = jedis.multi();
        t.set("hello", "world");
        jedis.close();
        jedis2 = pool.getResource();
        assertTrue(jedis == jedis2);
        assertEquals("jedis", jedis2.get("hello"));
    } catch (JedisConnectionException e) {
        if (jedis2 != null) {
            jedis2 = null;
        }
    } finally {
        jedis2.close();
        pool.destroy();
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisSentinelPool(redis.clients.jedis.JedisSentinelPool) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Test(org.junit.Test)

Example 10 with JedisConnectionException

use of redis.clients.jedis.exceptions.JedisConnectionException in project jstorm by alibaba.

the class RedisSinkBolt method retryGet.

private byte[] retryGet(byte[] key) {
    int retry = 0;
    byte[] ret;
    while (true) {
        Jedis jedis = null;
        try {
            jedis = pool.getResource();
            ret = jedis.get(key);
            return ret;
        } catch (JedisConnectionException e) {
            if (jedis != null) {
                pool.returnBrokenResource(jedis);
                jedis = null;
            }
            if (retry > retryLimit) {
                throw e;
            }
            retry++;
        } finally {
            if (jedis != null) {
                pool.returnResource(jedis);
            }
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException)

Aggregations

JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)34 Jedis (redis.clients.jedis.Jedis)14 IOException (java.io.IOException)8 Logger (org.apache.log4j.Logger)8 Test (org.junit.Test)7 JedisDataException (redis.clients.jedis.exceptions.JedisDataException)5 URI (java.net.URI)3 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)3 JedisShardInfo (redis.clients.jedis.JedisShardInfo)3 UsefulDataModel (com.sohu.tv.jedis.stat.model.UsefulDataModel)2 InetSocketAddress (java.net.InetSocketAddress)2 Socket (java.net.Socket)2 SSLParameters (javax.net.ssl.SSLParameters)2 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)2 BinaryJedis (redis.clients.jedis.BinaryJedis)2 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)2 Transaction (redis.clients.jedis.Transaction)2 RedisInputStream (redis.clients.util.RedisInputStream)2 ServerInfo (beans.dbaccess.ServerInfo)1 QueryRedisClusterDetailResponse (beans.response.QueryRedisClusterDetailResponse)1