本文整理匯總了Java中redis.clients.jedis.Pipeline.multi方法的典型用法代碼示例。如果您正苦於以下問題:Java Pipeline.multi方法的具體用法?Java Pipeline.multi怎麽用?Java Pipeline.multi使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.clients.jedis.Pipeline
的用法示例。
在下文中一共展示了Pipeline.multi方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: pipelineWithTransaction
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
public void pipelineWithTransaction() {
Jedis jedis = pool.getResource();
try {
Pipeline p = jedis.pipelined();
p.multi();
for (int i = 0; i < rowCount; i++) {
String key = RandomStringUtils.randomAlphabetic(8);
p.set(key, RandomStringUtils.randomNumeric(5));
p.expire(key, 5 * 60);
}
p.exec();
p.sync();
} catch (Exception e) {
pool.returnResource(jedis);
}
}
示例2: multiWithMassiveRequests
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@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();
}
}
示例3: multiWithSync
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void multiWithSync() {
jedis.set("foo", "314");
jedis.set("bar", "foo");
jedis.set("hello", "world");
Pipeline p = jedis.pipelined();
Response<String> r1 = p.get("bar");
p.multi();
Response<String> r2 = p.get("foo");
p.exec();
Response<String> r3 = p.get("hello");
p.sync();
// before multi
assertEquals("foo", r1.get());
// It should be readable whether exec's response was built or not
assertEquals("314", r2.get());
// after multi
assertEquals("world", r3.get());
}
示例4: getLastKnownValues
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public Map<ExternalId, Map<String, String>> getLastKnownValues(final List<ExternalId> securities) {
Map<ExternalId, Map<String, String>> result = Maps.newHashMap();
JedisPool jedisPool = _redisConnector.getJedisPool();
Jedis jedis = jedisPool.getResource();
Pipeline pipeline = jedis.pipelined();
//start transaction
pipeline.multi();
for (ExternalId identifier : securities) {
String redisKey = generateRedisKey(identifier.getScheme().getName(), identifier.getValue(), getNormalizationRuleSetId());
pipeline.hgetAll(redisKey);
}
Response<List<Object>> response = pipeline.exec();
pipeline.sync();
final Iterator<ExternalId> allSecItr = securities.iterator();
final Iterator<Object> responseItr = response.get().iterator();
while (responseItr.hasNext() && allSecItr.hasNext()) {
result.put(allSecItr.next(), filterBlackListedTicks((Map<String, String>) responseItr.next()));
}
jedisPool.returnResource(jedis);
return result;
}
示例5: popKeyFromZset
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
* Pop a ready room from "room_ready_set_<N>".
*/
public static final Tuple popKeyFromZset(String zsetName) {
Pipeline pipeline = JedisFactory.getJedis().pipelined();
try {
pipeline.watch(zsetName);
Response<Set<Tuple>> results = pipeline.zrangeWithScores(zsetName, 0, 0);
pipeline.multi();
pipeline.zremrangeByRank(zsetName, 0, 0);
pipeline.exec();
pipeline.sync();
Set<Tuple> values = results.get();
if (values.size() > 0) {
return values.iterator().next();
}
} catch (Exception e) {
try {
pipeline.discard();
} catch (Exception e1) {
}
e.printStackTrace();
}
return null;
}
示例6: testResetStateWhenInMultiWithinPipeline
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testResetStateWhenInMultiWithinPipeline() {
jedis.auth("foobared");
Pipeline p = jedis.pipelined();
p.multi();
p.set("foooo", "barrr");
jedis.resetState();
assertEquals(null, jedis.get("foooo"));
}
示例7: main
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
public static void main(String[] args) {
jedis.auth("gaoguangjin");
jedis.select(1);
jedis.flushDB();
jedis2.auth("gaoguangjin");
jedis2.select(1);
Transaction transaction = jedis2.multi();
jedis2.getClient().setConnectionTimeout(100000);
jedis3.auth("gaoguangjin");
jedis3.select(1);
Pipeline pipeline = jedis3.pipelined();
jedis3.getClient().setConnectionTimeout(100000);
pipeline.multi();
// 不要把注釋打開,否則慢的要死!!!
long start = System.currentTimeMillis();
/* jedis();
System.out.printf("jedis use %d sec \n", (System.currentTimeMillis() - start) / 1000);*/
start = System.currentTimeMillis();
transation(transaction);
System.out.printf("transation use %d sec \n", (System.currentTimeMillis() - start) / 1000);
start = System.currentTimeMillis();
piple();
System.out.printf("batch piple use %d sec \n", (System.currentTimeMillis() - start) / 1000);
// start = System.currentTimeMillis();
// pipleWithTransation(pipeline);
// System.out.printf("batch piple transation use %d sec \n", (System.currentTimeMillis() - start) / 1000);
}
示例8: multi
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void multi() {
Pipeline p = jedis.pipelined();
p.multi();
Response<Long> r1 = p.hincrBy("a", "f1", -1);
Response<Long> r2 = p.hincrBy("a", "f1", -2);
Response<List<Object>> r3 = p.exec();
List<Object> result = p.syncAndReturnAll();
assertEquals(new Long(-1), r1.get());
assertEquals(new Long(-3), r2.get());
assertEquals(4, result.size());
assertEquals("OK", result.get(0));
assertEquals("QUEUED", result.get(1));
assertEquals("QUEUED", result.get(2));
// 4th result is a list with the results from the multi
@SuppressWarnings("unchecked")
List<Object> multiResult = (List<Object>) result.get(3);
assertEquals(new Long(-1), multiResult.get(0));
assertEquals(new Long(-3), multiResult.get(1));
assertEquals(new Long(-1), r3.get().get(0));
assertEquals(new Long(-3), r3.get().get(1));
}
示例9: pipelineMultiShoudThrowJedisDataExceptionWhenAlreadyInMulti
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test(expected = JedisDataException.class)
public void pipelineMultiShoudThrowJedisDataExceptionWhenAlreadyInMulti() {
Pipeline pipeline = jedis.pipelined();
pipeline.multi();
pipeline.set("foo", "3");
pipeline.multi();
}
示例10: testDiscardInPipeline
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testDiscardInPipeline() {
Pipeline pipeline = jedis.pipelined();
pipeline.multi();
pipeline.set("foo", "bar");
Response<String> discard = pipeline.discard();
Response<String> get = pipeline.get("foo");
pipeline.sync();
discard.get();
get.get();
}
示例11: testCloseableWithMulti
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testCloseableWithMulti() throws IOException {
// we need to test with fresh instance of Jedis
Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500);
jedis2.auth("foobared");
Pipeline pipeline = jedis2.pipelined();
Response<String> retFuture1 = pipeline.set("a", "1");
Response<String> retFuture2 = pipeline.set("b", "2");
pipeline.multi();
pipeline.set("a", "a");
pipeline.set("b", "b");
pipeline.close();
try {
pipeline.exec();
fail("close should discard transaction");
} catch (JedisDataException e) {
assertTrue(e.getMessage().contains("EXEC without MULTI"));
// pass
}
// it shouldn't meet any exception
retFuture1.get();
retFuture2.get();
}
示例12: testCombPipelineTrans
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
public void testCombPipelineTrans() {// 0.099秒
Jedis jedis = new Jedis("120.25.241.144", 6379);
jedis.auth("b840fc02d52404542994");
long start = System.currentTimeMillis();
Pipeline pipeline = jedis.pipelined();
pipeline.multi();
for (int i = 0; i < 1000; i++) {
pipeline.set("n" + i, "n" + i);
System.out.println(i);
}
pipeline.exec();
pipeline.syncAndReturnAll();
long end = System.currentTimeMillis();
System.out.println("共花費:" + (end - start) / 1000.0 + "秒");
jedis.disconnect();
try {
Closeables.close(jedis, true);
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: test4combPipelineTrans
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void test4combPipelineTrans() {
long start = System.currentTimeMillis();
Pipeline pipeline = jedis.pipelined();
pipeline.multi();
for (int i = 0; i < 100000; i++) {
pipeline.set("" + i, "" + i);
}
pipeline.exec();
List<Object> results = pipeline.syncAndReturnAll();
long end = System.currentTimeMillis();
System.out.println("Pipelined transaction: " + ((end - start) / 1000.0) + " seconds");
}
示例14: testPipelinedTransactionResponse
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testPipelinedTransactionResponse() {
String key1 = "key1";
String val1 = "val1";
String key2 = "key2";
String val2 = "val2";
String key3 = "key3";
String field1 = "field1";
String field2 = "field2";
String field3 = "field3";
String field4 = "field4";
String value1 = "value1";
String value2 = "value2";
String value3 = "value3";
String value4 = "value4";
Map<String, String> hashMap = new HashMap<String, String>();
hashMap.put(field1, value1);
hashMap.put(field2, value2);
String key4 = "key4";
Map<String, String> hashMap1 = new HashMap<String, String>();
hashMap1.put(field3, value3);
hashMap1.put(field4, value4);
jedis.set(key1, val1);
jedis.set(key2, val2);
jedis.hmset(key3, hashMap);
jedis.hmset(key4, hashMap1);
Pipeline pipeline = jedis.pipelined();
pipeline.multi();
pipeline.get(key1);
pipeline.hgetAll(key2);
pipeline.hgetAll(key3);
pipeline.get(key4);
Response<List<Object>> response = pipeline.exec();
pipeline.sync();
List<Object> result = response.get();
assertEquals(4, result.size());
assertEquals("val1", result.get(0));
assertTrue(result.get(1) instanceof JedisDataException);
Map<String, String> hashMapReceived = (Map<String, String>) result.get(2);
Iterator<String> iterator = hashMapReceived.keySet().iterator();
String mapKey1 = iterator.next();
String mapKey2 = iterator.next();
assertFalse(iterator.hasNext());
verifyHasBothValues(mapKey1, mapKey2, field1, field2);
String mapValue1 = hashMapReceived.get(mapKey1);
String mapValue2 = hashMapReceived.get(mapKey2);
verifyHasBothValues(mapValue1, mapValue2, value1, value2);
assertTrue(result.get(3) instanceof JedisDataException);
}
示例15: before
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Override
Pipeline before(Jedis jedis) {
Pipeline pipeline = jedis.pipelined();
pipeline.multi();
return pipeline;
}