当前位置: 首页>>代码示例>>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;未经允许,请勿转载。