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


Java Jedis.multi方法代碼示例

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


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

示例1: testResetStateWithFullyExecutedTransaction

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

示例2: testCloseable

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

示例3: deleteMulti

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

示例4: getAndRemZRange

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

示例5: returnResourceShouldResetState

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void returnResourceShouldResetState() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000, "foobared");

  Jedis jedis = pool.getResource();
  try {
    jedis.set("hello", "jedis");
    Transaction t = jedis.multi();
    t.set("hello", "world");
  } finally {
    jedis.close();
  }

  Jedis jedis2 = pool.getResource();
  try {
    assertTrue(jedis == jedis2);
    assertEquals("jedis", jedis2.get("hello"));
  } finally {
    jedis2.close();
  }

  pool.destroy();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:28,代碼來源:JedisPoolTest.java

示例6: returnResourceShouldResetState

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void returnResourceShouldResetState() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
      "foobared", 2);

  Jedis jedis = pool.getResource();
  Jedis jedis2 = null;

  try {
    jedis.set("hello", "jedis");
    Transaction t = jedis.multi();
    t.set("hello", "world");
    pool.returnResource(jedis);

    jedis2 = pool.getResource();

    assertTrue(jedis == jedis2);
    assertEquals("jedis", jedis2.get("hello"));
  } catch (JedisConnectionException e) {
    if (jedis2 != null) {
      pool.returnBrokenResource(jedis2);
      jedis2 = null;
    }
  } finally {
    if (jedis2 != null) jedis2.close();

    pool.destroy();
  }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:33,代碼來源:JedisSentinelPoolTest.java

示例7: releaseLock

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * 釋放鎖
 *
 * @param lockName   鎖的key
 * @param identifier 釋放鎖的標識
 */
public boolean releaseLock(String lockName, String identifier){
    Jedis conn = null;
    String lockKey = lockPrefix + lockName;
    boolean retFlag = false;
    ShardedJedis shardedJedis = jedisPool.getResource();
    try {
        conn = shardedJedis.getShard(lockKey);
        while (true) {
            // 監視lock,準備開始事務
            conn.watch(lockKey);
            // 通過前麵返回的value值判斷是不是該鎖,若是該鎖,則刪除,釋放鎖
            if (identifier.equals(conn.get(lockKey))) {
                Transaction transaction = conn.multi();
                transaction.del(lockKey);
                List<Object> results = transaction.exec();
                if (results == null) {
                    continue;
                }
                retFlag = true;
            }
            conn.unwatch();
            break;
        }
    } catch (JedisException e) {
        LOGGER.error("releaseLock found exception", e);
    } finally {
        if (conn != null) {
            jedisPool.returnResource(shardedJedis);
        }
    }
    return retFlag;
}
 
開發者ID:bubicn,項目名稱:bubichain-sdk-java,代碼行數:39,代碼來源:DistributedLock.java


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