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");
}
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();
}
}
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();
}
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());
}
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();
}
}
}
Aggregations