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