当前位置: 首页>>代码示例>>Java>>正文


Java Response.get方法代码示例

本文整理汇总了Java中redis.clients.jedis.Response.get方法的典型用法代码示例。如果您正苦于以下问题:Java Response.get方法的具体用法?Java Response.get怎么用?Java Response.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在redis.clients.jedis.Response的用法示例。


在下文中一共展示了Response.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transactionResponseWithError

import redis.clients.jedis.Response; //导入方法依赖的package包/类
@Test
public void transactionResponseWithError() {
  Transaction t = jedis.multi();
  t.set("foo", "bar");
  Response<Set<String>> error = t.smembers("foo");
  Response<String> r = t.get("foo");
  List<Object> l = t.exec();
  assertEquals(JedisDataException.class, l.get(1).getClass());
  try {
    error.get();
    fail("We expect exception here!");
  } catch (JedisDataException e) {
    // that is fine we should be here
  }
  assertEquals(r.get(), "bar");
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:17,代码来源:TransactionCommandsTest.java

示例2: containsKeys

import redis.clients.jedis.Response; //导入方法依赖的package包/类
@Override
public boolean containsKeys(Collection<K> keys) {
    if (keys == null || keys.size() == 0) {
        return false;
    }
    // 使用 Redis 提供的管道进行批处理,提高效率
    Pipeline pipeline = jedisProxy.pipelined();
    Set<Response<Boolean>> responses = new HashSet<Response<Boolean>>(keys.size());
    for (K key : keys) {
        if (localMapCache != null && localMapCache.containsKey(key)) {
            continue;
        }
        responses.add(pipeline.hexists(SerializeUtil.serialize(getName()), SerializeUtil.serialize(key)));
    }
    if (responses.size() < 1) {
        return true;
    }
    pipeline.sync();
    for (Response<Boolean> response : responses) {
        if (!response.get()) {
            return false;
        }
    }
    return true;
}
 
开发者ID:ganpengyu,项目名称:gedis,代码行数:26,代码来源:ServerMapCache.java

示例3: multiWithMassiveRequests

import redis.clients.jedis.Response; //导入方法依赖的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();
  }
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:23,代码来源:PipeliningTest.java

示例4: testCloseable

import redis.clients.jedis.Response; //导入方法依赖的package包/类
@Test
public void testCloseable() 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.close();

  // it shouldn't meet any exception
  retFuture1.get();
  retFuture2.get();
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:17,代码来源:PipeliningTest.java

示例5: drainTo

import redis.clients.jedis.Response; //导入方法依赖的package包/类
public <T> int drainTo(String key, Collection<T> c, int maxElements, Class<T> classNm) {
    if (StringUtils.isEmpty(key)) {
        key = setKey;
    }
    String listKey = service.sPop(key, String.class);
    if (StringUtils.isEmpty(listKey)) {
        return 0;
    }
    INaviMultiRedis multi = service.multi(key);
    try {
        Transaction tran = multi.getTransaction();
        Response<List<byte[]>> response = tran.lrange(listKey.getBytes(), 0, maxElements - 1);
        tran.ltrim(listKey, maxElements, -1);
        tran.exec();
        List<byte[]> results = response.get();
        for (byte[] result : results) {
            c.add(jsonSerializer.getObjectFromBytes(result, classNm));
        }
        if (results.size() < maxElements) {
            removeKey(key, listKey);
        }
        return c.size();
    } finally {
        multi.returnObject();
    }
}
 
开发者ID:sunguangran,项目名称:navi,代码行数:27,代码来源:NaviNewRedisMutiKeyMessageQueue.java

示例6: drainTo

import redis.clients.jedis.Response; //导入方法依赖的package包/类
public <T> int drainTo(String key, Collection<T> c, int maxElements, Class<T> classNm) {
    INaviMultiRedis multi = service.multi(key);
    try {
        Transaction tran = multi.getTransaction();
        Response<List<byte[]>> response = tran.lrange(key.getBytes(), 0, maxElements - 1);
        tran.ltrim(key, maxElements, -1);
        tran.exec();
        List<byte[]> results = response.get();
        AlibabaJsonSerializer jsonSerializer = new AlibabaJsonSerializer();
        for (byte[] result : results) {
            c.add(jsonSerializer.getObjectFromBytes(result, classNm));
        }
        return c.size();
    } finally {
        multi.returnObject();
    }
}
 
开发者ID:sunguangran,项目名称:navi,代码行数:18,代码来源:NaviRedisMessageQueue.java

示例7: transactionResponseWithinPipeline

import redis.clients.jedis.Response; //导入方法依赖的package包/类
@Test(expected = JedisDataException.class)
public void transactionResponseWithinPipeline() {
  jedis.set("string", "foo");

  Transaction t = jedis.multi();
  Response<String> string = t.get("string");
  string.get();
  t.exec();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:10,代码来源:TransactionCommandsTest.java

示例8: hgetAllPipeline

import redis.clients.jedis.Response; //导入方法依赖的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));
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:16,代码来源:HashesCommandsTest.java

示例9: pipelineResponseWithinPipeline

import redis.clients.jedis.Response; //导入方法依赖的package包/类
@Test(expected = JedisDataException.class)
public void pipelineResponseWithinPipeline() {
  jedis.set("string", "foo");

  ShardedJedisPipeline p = jedis.pipelined();
  Response<String> string = p.get("string");
  string.get();
  p.sync();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:10,代码来源:ShardedJedisPipelineTest.java

示例10: get

import redis.clients.jedis.Response; //导入方法依赖的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();
}
 
开发者ID:spinnaker,项目名称:fiat,代码行数:28,代码来源:RedisPermissionsRepository.java

示例11: pipelineResponseWithinPipeline

import redis.clients.jedis.Response; //导入方法依赖的package包/类
@Test(expected = JedisDataException.class)
public void pipelineResponseWithinPipeline() {
  jedis.set("string", "foo");

  Pipeline p = jedis.pipelined();
  Response<String> string = p.get("string");
  string.get();
  p.sync();
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:10,代码来源:PipeliningTest.java

示例12: piplineWithError

import redis.clients.jedis.Response; //导入方法依赖的package包/类
@Test
public void piplineWithError() {
  Pipeline p = jedis.pipelined();
  p.set("foo", "bar");
  Response<Set<String>> error = p.smembers("foo");
  Response<String> r = p.get("foo");
  p.sync();
  try {
    error.get();
    fail();
  } catch (JedisDataException e) {
    // that is fine we should be here
  }
  assertEquals(r.get(), "bar");
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:16,代码来源:PipeliningTest.java

示例13: testDiscardInPipeline

import redis.clients.jedis.Response; //导入方法依赖的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();
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:12,代码来源:PipeliningTest.java

示例14: testEvalNestedLists

import redis.clients.jedis.Response; //导入方法依赖的package包/类
@Test
public void testEvalNestedLists() {
  String script = "return { {KEYS[1]} , {2} }";

  Pipeline p = jedis.pipelined();
  Response<Object> result = p.eval(script, 1, "key1");
  p.sync();

  List<?> results = (List<?>) result.get();
  assertThat((List<String>) results.get(0), listWithItem("key1"));
  assertThat((List<Long>) results.get(1), listWithItem(2L));
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:13,代码来源:PipeliningTest.java

示例15: testEvalNestedListsWithBinary

import redis.clients.jedis.Response; //导入方法依赖的package包/类
@Test
public void testEvalNestedListsWithBinary() {
  byte[] bScript = SafeEncoder.encode("return { {KEYS[1]} , {2} }");
  byte[] bKey = SafeEncoder.encode("key1");

  Pipeline p = jedis.pipelined();
  Response<Object> result = p.eval(bScript, 1, bKey);
  p.sync();

  List<?> results = (List<?>) result.get();
  assertThat((List<byte[]>) results.get(0), listWithItem(bKey));
  assertThat((List<Long>) results.get(1), listWithItem(2L));
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:14,代码来源:PipeliningTest.java


注:本文中的redis.clients.jedis.Response.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。