Search in sources :

Example 31 with Pipeline

use of redis.clients.jedis.Pipeline in project cachecloud by sohutv.

the class PipeliningTest method testJedisThowExceptionWhenInPipeline.

@Test(expected = JedisDataException.class)
public void testJedisThowExceptionWhenInPipeline() {
    Pipeline pipeline = jedis.pipelined();
    pipeline.set("foo", "3");
    jedis.get("somekey");
    fail("Can't use jedis instance when in Pipeline");
}
Also used : Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 32 with Pipeline

use of redis.clients.jedis.Pipeline in project cachecloud by sohutv.

the class PipeliningTest method multiWithMassiveRequests.

@Test
public void multiWithMassiveRequests() {
    Pipeline p = jedis.pipelined();
    p.multi();
    List<Response<?>> responseList = new ArrayList<Response<?>>();
    for (int i = 0; i < 100000; i++) {
        // any operation should be ok, but shouldn't forget about timeout
        responseList.add(p.setbit("test", 1, true));
    }
    Response<List<Object>> exec = p.exec();
    p.sync();
    // we don't need to check return value
    // if below codes run without throwing Exception, we're ok
    exec.get();
    for (Response<?> resp : responseList) {
        resp.get();
    }
}
Also used : Response(redis.clients.jedis.Response) Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 33 with Pipeline

use of redis.clients.jedis.Pipeline in project cachecloud by sohutv.

the class PipeliningTest method pipelineMultiShoudThrowJedisDataExceptionWhenAlreadyInMulti.

@Test(expected = JedisDataException.class)
public void pipelineMultiShoudThrowJedisDataExceptionWhenAlreadyInMulti() {
    Pipeline pipeline = jedis.pipelined();
    pipeline.multi();
    pipeline.set("foo", "3");
    pipeline.multi();
}
Also used : Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 34 with Pipeline

use of redis.clients.jedis.Pipeline in project cachecloud by sohutv.

the class PipeliningTest method testEvalWithBinary.

@Test
public void testEvalWithBinary() {
    String script = "return 'success!'";
    Pipeline p = jedis.pipelined();
    Response<Object> result = p.eval(SafeEncoder.encode(script));
    p.sync();
    assertArrayEquals(SafeEncoder.encode("success!"), (byte[]) result.get());
}
Also used : Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 35 with Pipeline

use of redis.clients.jedis.Pipeline in project storm by apache.

the class RedisMapState method updateStatesToRedis.

/**
     * {@inheritDoc}
     */
@Override
protected void updateStatesToRedis(Map<String, String> keyValues) {
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        RedisDataTypeDescription description = this.options.dataTypeDescription;
        switch(description.getDataType()) {
            case STRING:
                String[] keyValue = buildKeyValuesList(keyValues);
                jedis.mset(keyValue);
                if (this.options.expireIntervalSec > 0) {
                    Pipeline pipe = jedis.pipelined();
                    for (int i = 0; i < keyValue.length; i += 2) {
                        pipe.expire(keyValue[i], this.options.expireIntervalSec);
                    }
                    pipe.sync();
                }
                break;
            case HASH:
                jedis.hmset(description.getAdditionalKey(), keyValues);
                if (this.options.expireIntervalSec > 0) {
                    jedis.expire(description.getAdditionalKey(), this.options.expireIntervalSec);
                }
                break;
            default:
                throw new IllegalArgumentException("Cannot process such data type: " + description.getDataType());
        }
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) RedisDataTypeDescription(org.apache.storm.redis.common.mapper.RedisDataTypeDescription) Pipeline(redis.clients.jedis.Pipeline)

Aggregations

Pipeline (redis.clients.jedis.Pipeline)77 Test (org.junit.Test)72 Jedis (redis.clients.jedis.Jedis)12 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)6 JedisDataException (redis.clients.jedis.exceptions.JedisDataException)6 HashMap (java.util.HashMap)5 Set (java.util.Set)3 Response (redis.clients.jedis.Response)3 LinkedHashMap (java.util.LinkedHashMap)2 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)1 BasePinpointTest (com.navercorp.pinpoint.test.junit4.BasePinpointTest)1 RedisDataTypeDescription (org.apache.storm.redis.common.mapper.RedisDataTypeDescription)1 RedisClusterStateUpdater (org.apache.storm.redis.trident.state.RedisClusterStateUpdater)1 RedisState (org.apache.storm.redis.trident.state.RedisState)1 RedisStateUpdater (org.apache.storm.redis.trident.state.RedisStateUpdater)1 ISqlTridentDataSource (org.apache.storm.sql.runtime.ISqlTridentDataSource)1 StateUpdater (org.apache.storm.trident.state.StateUpdater)1 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)1