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


Java Transaction類代碼示例

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


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

示例1: setJedisMultiCommand

import redis.clients.jedis.Transaction; //導入依賴的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;

}
 
開發者ID:longcoding,項目名稱:undefined-gateway,代碼行數:20,代碼來源:ApplicationRatelimitInterceptor.java

示例2: setJedisMultiCommand

import redis.clients.jedis.Transaction; //導入依賴的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;
}
 
開發者ID:longcoding,項目名稱:undefined-gateway,代碼行數:12,代碼來源:ServiceCapacityInterceptor.java

示例3: hincrby

import redis.clients.jedis.Transaction; //導入依賴的package包/類
@Test public void hincrby() {
    // GIVEN
    Transaction tr = this.jedis.multi();

    // WHEN
    Response<Long> result1 = tr.hincrBy(KEY, FIELD, 3);
    Response<Long> result2 = tr.hincrBy(KEY, FIELD, 4);
    List<Object> results = tr.exec();

    // THEN
    String value = this.jedis.hget(KEY, FIELD);
    assertEquals("7", value);

    assertEquals(2, results.size());
    assertEquals(3, (long) results.get(0));
    assertEquals(7, (long) results.get(1));

    assertEquals(3, (long) result1.get());
    assertEquals(7, (long) result2.get());
}
 
開發者ID:vdurmont,項目名稱:fake-jedis,代碼行數:21,代碼來源:FakeTransactionTest.java

示例4: testResetStateWithFullyExecutedTransaction

import redis.clients.jedis.Transaction; //導入依賴的package包/類
@Test
public void testResetStateWithFullyExecutedTransaction() {
  Jedis jedis2 = new Jedis(jedis.getClient().getHost(), jedis.getClient().getPort());
  jedis2.auth("foobared");

  Transaction t = jedis2.multi();
  t.set("mykey", "foo");
  t.get("mykey");

  List<Object> resp = t.exec();
  assertNotNull(resp);
  assertEquals(2, resp.size());

  jedis2.resetState();
  jedis2.close();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:17,代碼來源:TransactionCommandsTest.java

示例5: transactionResponseWithError

import redis.clients.jedis.Transaction; //導入依賴的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

示例6: execGetResponse

import redis.clients.jedis.Transaction; //導入依賴的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());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:18,代碼來源:TransactionCommandsTest.java

示例7: select

import redis.clients.jedis.Transaction; //導入依賴的package包/類
@Test
public void select() {
  jedis.select(1);
  jedis.set("foo", "bar");
  jedis.watch("foo");
  Transaction t = jedis.multi();
  t.select(0);
  t.set("bar", "foo");

  Jedis jedis2 = createJedis();
  jedis2.select(1);
  jedis2.set("foo", "bar2");

  List<Object> results = t.exec();
  if(results.isEmpty()){
    results = null;
  }
  assertNull(results);
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:20,代碼來源:TransactionCommandsTest.java

示例8: testCloseable

import redis.clients.jedis.Transaction; //導入依賴的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");

  Transaction transaction = jedis2.multi();
  transaction.set("a", "1");
  transaction.set("b", "2");

  transaction.close();

  try {
    transaction.exec();
    fail("close should discard transaction");
  } catch (JedisDataException e) {
    assertTrue(e.getMessage().contains("EXEC without MULTI"));
    // pass
  }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:21,代碼來源:TransactionCommandsTest.java

示例9: testExec

import redis.clients.jedis.Transaction; //導入依賴的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();
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:20,代碼來源:JedisTransactionInstrumentationTest.java

示例10: testDiscard

import redis.clients.jedis.Transaction; //導入依賴的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();
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:20,代碼來源:JedisTransactionInstrumentationTest.java

示例11: testCloseDiscards

import redis.clients.jedis.Transaction; //導入依賴的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();
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:20,代碼來源:JedisTransactionInstrumentationTest.java

示例12: deleteMulti

import redis.clients.jedis.Transaction; //導入依賴的package包/類
@Override
public boolean deleteMulti(String... keys) {
  Jedis jedis = null;
  try {
    jedis = pool.getResource();
    Transaction trans = jedis.multi();
    for (String key : keys) {
      trans.del(key.getBytes());
    }
    trans.exec();
    pool.returnResource(jedis);
  } catch (Exception e) {
    LOGGER.warn("Failed to delete key from cache {0}", keys, e);
    pool.returnBrokenResource(jedis);
    return false;
  }
  return true;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:19,代碼來源:RedisMemcacheService.java

示例13: getAndRemZRange

import redis.clients.jedis.Transaction; //導入依賴的package包/類
public Set<String> getAndRemZRange(String key, long score) {
  Jedis jedis = null;
  try {
    jedis = pool.getResource();
    Transaction trans = jedis.multi();
    trans.zrangeByScore(key.getBytes(), MIN_INF, SafeEncoder.encode(String.valueOf(score)));
    trans.zremrangeByScore(key.getBytes(), MIN_INF, SafeEncoder.encode(String.valueOf(score)));
    List<Object> response = trans.exec();
    Set<byte[]> data = (Set<byte[]>) response.get(0);
    Set<String> members = new LinkedHashSet<>(data.size());
    for (byte[] d : data) {
      members.add(new String(d));
    }
    pool.returnResource(jedis);
    return members;
  } catch (Exception e) {
    LOGGER.warn("Failed to get zrem keys from cache {0}:{1}", key, score, e);
    pool.returnBrokenResource(jedis);
    throw e;
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:22,代碼來源:RedisMemcacheService.java

示例14: deleteItem0

import redis.clients.jedis.Transaction; //導入依賴的package包/類
private void deleteItem0() {
    int selectedIndex = lstValues.getSelectionModel().getSelectedIndex();

    if (selectedIndex < 0) {
        return;
    }

    int listIndex = selectedIndex + currentFrom;

    try {
        JedisManager.withJedis(jedis -> {
            String toBeDeletedValue = "__TO_BE_DELETED/" + System.currentTimeMillis();
            jedis.watch(currentKey);
            Transaction transaction = jedis.multi();
            transaction.lset(currentKey, listIndex, toBeDeletedValue);
            transaction.lrem(currentKey, 1, toBeDeletedValue);
            transaction.exec();
        });
    } catch (Exception e) {
        LOG.error("delete failed", e);
        Fx.error(I18n.getString("title_op_fail"), I18n.getString("list_msg_op_failed"));
    }

    refreshList();
}
 
開發者ID:yiding-he,項目名稱:redisfx,代碼行數:26,代碼來源:ListTabController.java

示例15: doRelease

import redis.clients.jedis.Transaction; //導入依賴的package包/類
@Override
protected void doRelease(String token) {
    jedisClient.watch(lockName);

    String currentToken = jedisClient.get(lockName);
    if (currentToken == null){
        jedisClient.unwatch();
        return;
    }

    if (currentToken.equals(token)) {
        Transaction t = jedisClient.multi();
        t.del(lockName);
        t.exec();
    } else {
        jedisClient.unwatch();
    }
}
 
開發者ID:wushibin,項目名稱:redislock,代碼行數:19,代碼來源:RedisLock.java


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