Search in sources :

Example 21 with Transaction

use of redis.clients.jedis.Transaction in project grakn by graknlabs.

the class RedisIndexStorage method popIds.

@Override
public Set<ConceptId> popIds(Keyspace keyspace, String index) {
    String idKey = getConceptIdsKey(keyspace, index);
    return redisStorage.contactRedis(jedis -> {
        Transaction tx = jedis.multi();
        Response<Set<String>> responseIds = tx.smembers(idKey);
        tx.del(idKey);
        tx.exec();
        return responseIds.get().stream().map(ConceptId::of).collect(Collectors.toSet());
    });
}
Also used : Set(java.util.Set) Transaction(redis.clients.jedis.Transaction)

Example 22 with Transaction

use of redis.clients.jedis.Transaction in project leopard by tanhaichao.

the class RedisImpl method append.

@Override
public boolean append(final List<String> keyList, final List<String> valueList, final int seconds) {
    RedisUtil.checkList(keyList, valueList);
    return (Boolean) this.execute(new Invoker() {

        @Override
        public Object execute(Jedis jedis) {
            Transaction transaction = jedis.multi();
            for (int i = 0; i < keyList.size(); i++) {
                transaction.append(keyList.get(i), valueList.get(i));
                transaction.expire(keyList.get(i), seconds);
            }
            transaction.exec();
            return true;
        }
    });
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction)

Example 23 with Transaction

use of redis.clients.jedis.Transaction in project leopard by tanhaichao.

the class RedisTransactionTest method test.

public void test(int threadId) {
    String key1 = KEY_PREFIX + "key1";
    String value = "value:" + threadId + ";";
    // redis.set(key1, value);
    // System.out.println("getResource:" + threadId);
    Jedis jedis = redis.getResource();
    {
        Transaction transaction = jedis.multi();
        transaction.set(key1, value + "1");
        transaction.discard();
    }
    {
        Transaction transaction = jedis.multi();
        Response<String> value2 = transaction.get(key1);
        transaction.set(key1, value + "2");
        transaction.exec();
        // System.out.println("value:" + value2.get());
        Assert.assertEquals(value, value2.get());
    }
    System.out.println("threadId:" + threadId + " value:" + redis.get(key1));
    Assert.assertEquals(value + "2", redis.get(key1));
}
Also used : Response(redis.clients.jedis.Response) Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction)

Example 24 with Transaction

use of redis.clients.jedis.Transaction in project gitblit by gitblit.

the class RedisTicketService method renameImpl.

@Override
protected boolean renameImpl(RepositoryModel oldRepository, RepositoryModel newRepository) {
    Jedis jedis = pool.getResource();
    if (jedis == null) {
        return false;
    }
    boolean success = false;
    try {
        Set<String> oldKeys = jedis.keys(oldRepository.name + ":*");
        Transaction t = jedis.multi();
        for (String oldKey : oldKeys) {
            String newKey = newRepository.name + oldKey.substring(oldKey.indexOf(':'));
            t.rename(oldKey, newKey);
        }
        t.exec();
        success = true;
    } catch (JedisException e) {
        log.error("failed to rename tickets in Redis @ " + getUrl(), e);
        pool.returnBrokenResource(jedis);
        jedis = null;
    } finally {
        if (jedis != null) {
            pool.returnResource(jedis);
        }
    }
    return success;
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisException(redis.clients.jedis.exceptions.JedisException) Transaction(redis.clients.jedis.Transaction)

Example 25 with Transaction

use of redis.clients.jedis.Transaction in project cachecloud by sohutv.

the class TransactionCommandsTest method testCloseable.

@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
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) Test(org.junit.Test)

Aggregations

Transaction (redis.clients.jedis.Transaction)42 Test (org.junit.Test)32 Jedis (redis.clients.jedis.Jedis)19 Set (java.util.Set)7 JedisDataException (redis.clients.jedis.exceptions.JedisDataException)6 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)4 JedisException (redis.clients.jedis.exceptions.JedisException)4 Response (redis.clients.jedis.Response)3 ArrayList (java.util.ArrayList)2 JedisPool (redis.clients.jedis.JedisPool)2 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)2 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)2 TicketModel (com.gitblit.models.TicketModel)1 Change (com.gitblit.models.TicketModel.Change)1 ResourceMetadata (org.opennms.newts.cassandra.search.ResourceMetadata)1