本文整理汇总了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");
}
示例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;
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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));
}
示例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();
}
示例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();
}
示例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();
}
示例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");
}
示例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();
}
示例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));
}
示例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));
}