當前位置: 首頁>>代碼示例>>Java>>正文


Java Pipeline.hmget方法代碼示例

本文整理匯總了Java中redis.clients.jedis.Pipeline.hmget方法的典型用法代碼示例。如果您正苦於以下問題:Java Pipeline.hmget方法的具體用法?Java Pipeline.hmget怎麽用?Java Pipeline.hmget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.Pipeline的用法示例。


在下文中一共展示了Pipeline.hmget方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: pipelineBinarySafeHashCommands

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void pipelineBinarySafeHashCommands() {
  jedis.hset("key".getBytes(), "f1".getBytes(), "v111".getBytes());
  jedis.hset("key".getBytes(), "f22".getBytes(), "v2222".getBytes());

  Pipeline p = jedis.pipelined();
  Response<Map<byte[], byte[]>> fmap = p.hgetAll("key".getBytes());
  Response<Set<byte[]>> fkeys = p.hkeys("key".getBytes());
  Response<List<byte[]>> fordered = p.hmget("key".getBytes(), "f22".getBytes(), "f1".getBytes());
  Response<List<byte[]>> fvals = p.hvals("key".getBytes());
  p.sync();

  assertNotNull(fmap.get());
  // we have to do these strange contortions because byte[] is not a very
  // good key
  // for a java Map. It only works with equality (you need the exact key
  // object to retrieve
  // the value) I recommend we switch to using ByteBuffer or something
  // similar:
  // http://stackoverflow.com/questions/1058149/using-a-byte-array-as-hashmap-key-java
  Map<byte[], byte[]> map = fmap.get();
  Set<byte[]> mapKeys = map.keySet();
  Iterator<byte[]> iterMap = mapKeys.iterator();
  byte[] firstMapKey = iterMap.next();
  byte[] secondMapKey = iterMap.next();
  assertFalse(iterMap.hasNext());
  verifyHasBothValues(firstMapKey, secondMapKey, "f1".getBytes(), "f22".getBytes());
  byte[] firstMapValue = map.get(firstMapKey);
  byte[] secondMapValue = map.get(secondMapKey);
  verifyHasBothValues(firstMapValue, secondMapValue, "v111".getBytes(), "v2222".getBytes());

  assertNotNull(fkeys.get());
  Iterator<byte[]> iter = fkeys.get().iterator();
  byte[] firstKey = iter.next();
  byte[] secondKey = iter.next();
  assertFalse(iter.hasNext());
  verifyHasBothValues(firstKey, secondKey, "f1".getBytes(), "f22".getBytes());

  assertNotNull(fordered.get());
  assertArrayEquals("v2222".getBytes(), fordered.get().get(0));
  assertArrayEquals("v111".getBytes(), fordered.get().get(1));

  assertNotNull(fvals.get());
  assertEquals(2, fvals.get().size());
  byte[] firstValue = fvals.get().get(0);
  byte[] secondValue = fvals.get().get(1);
  verifyHasBothValues(firstValue, secondValue, "v111".getBytes(), "v2222".getBytes());
}
 
開發者ID:sohutv,項目名稱:cachecloud,代碼行數:49,代碼來源:PipeliningTest.java


注:本文中的redis.clients.jedis.Pipeline.hmget方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。