Search in sources :

Example 6 with RedisOutputStream

use of redis.clients.util.RedisOutputStream in project jedis by xetorthio.

the class ProtocolBenchmark method measureCommand.

private static long measureCommand() throws Exception {
    long duration = 0;
    byte[] KEY = "123456789".getBytes();
    byte[] VAL = "FooBar".getBytes();
    for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
        RedisOutputStream out = new RedisOutputStream(new ByteArrayOutputStream(8192));
        long start = System.nanoTime();
        Protocol.sendCommand(out, Protocol.Command.SET, KEY, VAL);
        duration += (System.nanoTime() - start);
    }
    return duration;
}
Also used : RedisOutputStream(redis.clients.util.RedisOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with RedisOutputStream

use of redis.clients.util.RedisOutputStream 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 8 with RedisOutputStream

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

the class ProtocolBenchmark method measureCommand.

private static long measureCommand() throws Exception {
    long duration = 0;
    byte[] KEY = "123456789".getBytes();
    byte[] VAL = "FooBar".getBytes();
    for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
        RedisOutputStream out = new RedisOutputStream(new ByteArrayOutputStream(8192));
        long start = System.nanoTime();
        Protocol.sendCommand(out, Protocol.Command.SET, KEY, VAL);
        duration += (System.nanoTime() - start);
    }
    return duration;
}
Also used : RedisOutputStream(redis.clients.util.RedisOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

RedisOutputStream (redis.clients.util.RedisOutputStream)8 IOException (java.io.IOException)4 PipedOutputStream (java.io.PipedOutputStream)4 Test (org.junit.Test)4 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 PipedInputStream (java.io.PipedInputStream)2 InetSocketAddress (java.net.InetSocketAddress)2 Socket (java.net.Socket)2 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)2 RedisInputStream (redis.clients.util.RedisInputStream)2 SSLSocket (javax.net.ssl.SSLSocket)1