本文整理汇总了Java中redis.clients.jedis.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于redis.clients.jedis包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setJedisMultiCommand
import redis.clients.jedis.Response; //导入依赖的package包/类
@Override
public Map<String, Response<Long>> setJedisMultiCommand(Transaction jedisMulti) {
Response<Long> applicationDailyRateLimit =
jedisMulti.hincrBy(Const.REDIS_APP_RATELIMIT_DAILY, this.requestInfo.getAppId(), -1);
Response<Long> applicationMinutelyRateLimit =
jedisMulti.hincrBy(Const.REDIS_APP_RATELIMIT_MINUTELY, this.requestInfo.getAppId(), -1);
Response<Long> applicationDailyRateLimitTTL = jedisMulti.ttl(Const.REDIS_APP_RATELIMIT_DAILY);
Response<Long> applicationMinutelyRateLimitTTL = jedisMulti.ttl(Const.REDIS_APP_RATELIMIT_MINUTELY);
Map<String, Response<Long>> appRatelimit = Maps.newHashMap();
appRatelimit.put(Const.REDIS_APP_RATELIMIT_DAILY, applicationDailyRateLimit);
appRatelimit.put(Const.REDIS_APP_RATELIMIT_MINUTELY, applicationMinutelyRateLimit);
appRatelimit.put(Const.REDIS_APP_RATELIMIT_DAILY_TTL, applicationDailyRateLimitTTL);
appRatelimit.put(Const.REDIS_APP_RATELIMIT_MINUTELY_TTL, applicationMinutelyRateLimitTTL);
return appRatelimit;
}
示例2: setJedisMultiCommand
import redis.clients.jedis.Response; //导入依赖的package包/类
@Override
public Map<String, Response<Long>> setJedisMultiCommand(Transaction jedisMulti) {
Response<Long> serviceDailyRatelimit = jedisMulti.hincrBy(Const.REDIS_SERVICE_CAPACITY_DAILY, this.requestInfo.getServiceId(), -1);
Response<Long> serviceDailyTTL = jedisMulti.ttl(Const.REDIS_SERVICE_CAPACITY_DAILY);
Map<String, Response<Long>> serviceRatelimit = Maps.newHashMap();
serviceRatelimit.put(Const.REDIS_SERVICE_CAPACITY_DAILY, serviceDailyRatelimit);
serviceRatelimit.put(Const.REDIS_SERVICE_CAPACITY_DAILY_TTL, serviceDailyTTL);
return serviceRatelimit;
}
示例3: 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");
}
示例4: execGetResponse
import redis.clients.jedis.Response; //导入依赖的package包/类
@Test
public void execGetResponse() {
Transaction t = jedis.multi();
t.set("foo", "bar");
t.smembers("foo");
t.get("foo");
List<Response<?>> lr = t.execGetResponse();
try {
lr.get(1).get();
fail("We expect exception here!");
} catch (JedisDataException e) {
// that is fine we should be here
}
assertEquals("bar", lr.get(2).get());
}
示例5: testExec
import redis.clients.jedis.Response; //导入依赖的package包/类
@Test
public void testExec() throws Exception {
int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
String key = presetElementKeys.get(rnd);
String value = String.valueOf(presetElements.get(key));
Transaction transaction = jedis.multi();
Snapshot snapshot = commandTracker.snapshot();
Snapshot discardSnapshot = discardTracker.snapshot();
Snapshot txsnapshot = execTracker.snapshot();
txsnapshot.increment();
Response<Long> added = transaction.sadd(key, value);
transaction.exec();
assertEquals(1, (long) added.get());
txsnapshot.validate();
snapshot.validate();
discardSnapshot.validate();
}
示例6: testDiscard
import redis.clients.jedis.Response; //导入依赖的package包/类
@Test
public void testDiscard() throws Exception {
int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
String key = presetElementKeys.get(rnd);
String value = String.valueOf(presetElements.get(key));
Transaction transaction = jedis.multi();
Snapshot snapshot = commandTracker.snapshot();
Snapshot discardSnapshot = discardTracker.snapshot();
Snapshot txsnapshot = execTracker.snapshot();
discardSnapshot.increment();
Response<Long> added = transaction.sadd(key, value);
transaction.discard();
assertNull(jedis.get(key));
txsnapshot.validate();
snapshot.validate();
discardSnapshot.validate();
}
示例7: testCloseDiscards
import redis.clients.jedis.Response; //导入依赖的package包/类
@Test
public void testCloseDiscards() throws Exception {
int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
String key = presetElementKeys.get(rnd);
String value = String.valueOf(presetElements.get(key));
Transaction transaction = jedis.multi();
Snapshot snapshot = commandTracker.snapshot();
Snapshot discardSnapshot = discardTracker.snapshot();
Snapshot txsnapshot = execTracker.snapshot();
discardSnapshot.increment();
Response<Long> added = transaction.sadd(key, value);
transaction.close();
assertNull(jedis.get(key));
txsnapshot.validate();
snapshot.validate();
discardSnapshot.validate();
}
示例8: testSync
import redis.clients.jedis.Response; //导入依赖的package包/类
@Test
public void testSync() throws Exception {
int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
String key = presetElementKeys.get(rnd);
String value = String.valueOf(presetElements.get(key));
Pipeline pipeline = jedis.pipelined();
Snapshot snapshot = commandTracker.snapshot();
Snapshot discardSnapshot = discardTracker.snapshot();
Snapshot txsnapshot = execTracker.snapshot();
Snapshot pipelineSnapshot = pipelineTracker.snapshot();
pipelineSnapshot.increment();
Response<Long> added = pipeline.sadd(key, value);
pipeline.sync();
assertEquals(1, (long) added.get());
pipelineSnapshot.validate();
txsnapshot.validate();
snapshot.validate();
discardSnapshot.validate();
}
示例9: testCloseSyncs
import redis.clients.jedis.Response; //导入依赖的package包/类
@Test
public void testCloseSyncs() throws Exception {
int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
String key = presetElementKeys.get(rnd);
String value = String.valueOf(presetElements.get(key));
Pipeline pipeline = jedis.pipelined();
Snapshot snapshot = commandTracker.snapshot();
Snapshot discardSnapshot = discardTracker.snapshot();
Snapshot txsnapshot = execTracker.snapshot();
Snapshot pipelineSnapshot = pipelineTracker.snapshot();
pipelineSnapshot.increment();
Response<Long> added = pipeline.sadd(key, value);
pipeline.close();
assertEquals(1, (long) added.get());
pipelineSnapshot.validate();
txsnapshot.validate();
snapshot.validate();
discardSnapshot.validate();
}
示例10: 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;
}
示例11: gets
import redis.clients.jedis.Response; //导入依赖的package包/类
@Override
public Map<K, V> gets(Collection<K> keys) {
Map<K, V> result = new HashMap<>(keys.size());
Pipeline pipeline = jedisProxy.pipelined();
byte[] keyBytes = SerializeUtil.serialize(getName());
Map<K, Response<byte[]>> responseMap = new HashMap<>(keys.size());
for (K key : keys) {
if (localMapCache != null && localMapCache.containsKey(key)) {
result.put(key, localMapCache.get(key));
continue;
}
responseMap.put(key, pipeline.hget(keyBytes, SerializeUtil.serialize(key)));
}
if (responseMap.size() < 1) {
return result;
}
pipeline.sync();
for (Map.Entry<K, Response<byte[]>> entry : responseMap.entrySet()) {
result.put(entry.getKey(), (V) SerializeUtil.deserialize(entry.getValue().get()));
}
return result;
}
示例12: 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();
}
}
示例13: 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();
}
示例14: getAllById
import redis.clients.jedis.Response; //导入依赖的package包/类
@Override
public Map<String, UserPermission> getAllById() {
Table<String, ResourceType, Response<Map<String, String>>> responseTable = getAllFromRedis();
if (responseTable == null) {
return new HashMap<>(0);
}
Map<String, UserPermission> allById = new HashMap<>(responseTable.rowKeySet().size());
RawUserPermission rawUnrestricted = new RawUserPermission(responseTable.row(UNRESTRICTED));
UserPermission unrestrictedUser = getUserPermission(UNRESTRICTED, rawUnrestricted);
for (String userId : responseTable.rowKeySet()) {
RawUserPermission rawUser = new RawUserPermission(responseTable.row(userId));
UserPermission permission = getUserPermission(userId, rawUser);
allById.put(userId, permission.merge(unrestrictedUser));
}
return allById;
}
示例15: getAllFromRedis
import redis.clients.jedis.Response; //导入依赖的package包/类
private Table<String, ResourceType, Response<Map<String, String>>> getAllFromRedis(Set<String> userIds) {
if (userIds.size() == 0) {
return HashBasedTable.create();
}
try (Jedis jedis = jedisSource.getJedis()) {
Table<String, ResourceType, Response<Map<String, String>>> responseTable =
ArrayTable.create(userIds, new ArrayIterator<>(ResourceType.values()));
Pipeline p = jedis.pipelined();
for (String userId : userIds) {
for (ResourceType r : ResourceType.values()) {
responseTable.put(userId, r, p.hgetAll(userKey(userId, r)));
}
}
p.sync();
return responseTable;
} catch (Exception e) {
log.error("Storage exception reading all entries.", e);
}
return null;
}