本文整理汇总了Java中redis.clients.jedis.Pipeline.hgetAll方法的典型用法代码示例。如果您正苦于以下问题:Java Pipeline.hgetAll方法的具体用法?Java Pipeline.hgetAll怎么用?Java Pipeline.hgetAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Pipeline
的用法示例。
在下文中一共展示了Pipeline.hgetAll方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: hgetAllPipeline
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void hgetAllPipeline() {
Map<byte[], byte[]> bh = new HashMap<byte[], byte[]>();
bh.put(bbar, bcar);
bh.put(bcar, bbar);
jedis.hmset(bfoo, bh);
Pipeline pipeline = jedis.pipelined();
Response<Map<byte[], byte[]>> bhashResponse = pipeline.hgetAll(bfoo);
pipeline.sync();
Map<byte[], byte[]> bhash = bhashResponse.get();
assertEquals(2, bhash.size());
assertArrayEquals(bcar, bhash.get(bbar));
assertArrayEquals(bbar, bhash.get(bcar));
}
示例3: get
import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public Optional<UserPermission> get(@NonNull String id) {
try (Jedis jedis = jedisSource.getJedis()) {
RawUserPermission userResponseMap = new RawUserPermission();
RawUserPermission unrestrictedResponseMap = new RawUserPermission();
Pipeline p = jedis.pipelined();
Response<Boolean> isUserInRepo = p.sismember(allUsersKey(), id);
for (ResourceType r : ResourceType.values()) {
Response<Map<String, String>> resourceMap = p.hgetAll(userKey(id, r));
userResponseMap.put(r, resourceMap);
Response<Map<String, String>> unrestrictedMap = p.hgetAll(unrestrictedUserKey(r));
unrestrictedResponseMap.put(r, unrestrictedMap);
}
p.sync();
if (!isUserInRepo.get()) {
return Optional.empty();
}
UserPermission unrestrictedUser = getUserPermission(UNRESTRICTED, unrestrictedResponseMap);
return Optional.of(getUserPermission(id, userResponseMap).merge(unrestrictedUser));
} catch (Exception e) {
log.error("Storage exception reading " + id + " entry.", e);
}
return Optional.empty();
}
示例4: 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());
}
示例5: 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);
}