Search in sources :

Example 26 with RedisInputStream

use of redis.clients.util.RedisInputStream in project cachecloud by sohutv.

the class Connection method connect.

public void connect() {
    if (!isConnected()) {
        try {
            socket = new Socket();
            // ->@wjw_add
            socket.setReuseAddress(true);
            // Will monitor the TCP connection is
            socket.setKeepAlive(true);
            // valid
            // Socket buffer Whetherclosed, to
            socket.setTcpNoDelay(true);
            // ensure timely delivery of data
            // Control calls close () method,
            socket.setSoLinger(true, 0);
            // the underlying socket is closed
            // immediately
            // <-@wjw_add
            socket.connect(new InetSocketAddress(host, port), connectionTimeout);
            socket.setSoTimeout(soTimeout);
            outputStream = new RedisOutputStream(socket.getOutputStream());
            inputStream = new RedisInputStream(socket.getInputStream());
        } catch (IOException ex) {
            UsefulDataCollector.collectException(ex, getHostPort(), System.currentTimeMillis());
            broken = true;
            throw new JedisConnectionException(ex);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) RedisOutputStream(redis.clients.util.RedisOutputStream) RedisInputStream(redis.clients.util.RedisInputStream) IOException(java.io.IOException) Socket(java.net.Socket) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException)

Example 27 with RedisInputStream

use of redis.clients.util.RedisInputStream in project cachecloud by sohutv.

the class ProtocolBenchmark method measureInputMulti.

private static long measureInputMulti() throws Exception {
    long duration = 0;
    InputStream is = new ByteArrayInputStream("*4\r\n$3\r\nfoo\r\n$13\r\nbarbarbarfooz\r\n$5\r\nHello\r\n$5\r\nWorld\r\n".getBytes());
    RedisInputStream in = new RedisInputStream(is);
    for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
        long start = System.nanoTime();
        Protocol.read(in);
        duration += (System.nanoTime() - start);
        in.reset();
    }
    return duration;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RedisInputStream(redis.clients.util.RedisInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RedisInputStream(redis.clients.util.RedisInputStream)

Aggregations

RedisInputStream (redis.clients.util.RedisInputStream)27 ByteArrayInputStream (java.io.ByteArrayInputStream)25 InputStream (java.io.InputStream)25 BufferedInputStream (java.io.BufferedInputStream)19 PipedInputStream (java.io.PipedInputStream)19 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)6 List (java.util.List)6 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 Socket (java.net.Socket)2 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)2 RedisOutputStream (redis.clients.util.RedisOutputStream)2 JedisBusyException (redis.clients.jedis.exceptions.JedisBusyException)1