Search in sources :

Example 91 with Transaction

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

the class JedisPoolTest method returnResourceShouldResetState.

@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());
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisPool(redis.clients.jedis.JedisPool) Test(org.junit.Test)

Example 92 with Transaction

use of redis.clients.jedis.Transaction in project opennms by OpenNMS.

the class RedisResourceMetadataCache method merge.

@Override
public void merge(Context context, Resource resource, ResourceMetadata metadata) {
    final Optional<ResourceMetadata> o = get(context, resource);
    try (Jedis jedis = m_pool.getResource()) {
        if (!o.isPresent()) {
            final ResourceMetadata newMetadata = new ResourceMetadata();
            newMetadata.merge(metadata);
            final Transaction t = jedis.multi();
            final byte[] key = key(METADATA_PREFIX, context.getId(), resource.getId());
            t.set(key, conf.asByteArray(newMetadata));
            // Index the key, element by element, in order to support calls to getResourceIdsWithPrefix()
            final List<String> elements = Lists.newArrayList(SEARCH_PREFIX, context.getId());
            for (String el : m_resourceIdSplitter.splitIdIntoElements(resource.getId())) {
                elements.add(el);
                t.lpush(m_resourceIdSplitter.joinElementsToId(elements).getBytes(), key);
            }
            // Update the keys in transaction
            t.exec();
        } else if (o.get().merge(metadata)) {
            // Update the value stored in the cache if it was changed as a result of the merge
            jedis.set(key(METADATA_PREFIX, context.getId(), resource.getId()), conf.asByteArray(o.get()));
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction) ResourceMetadata(org.opennms.newts.cassandra.search.ResourceMetadata)

Example 93 with Transaction

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

the class RedisImpl method append.

@Override
public boolean append(final String key, final String value, final int seconds) {
    return (Boolean) this.execute(new Invoker() {

        @Override
        public Object execute(Jedis jedis) {
            Transaction transaction = jedis.multi();
            transaction.append(key, value);
            transaction.expire(key, seconds);
            transaction.exec();
            return true;
        }
    });
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction)

Example 94 with Transaction

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

the class RedisImpl method set.

@Override
public boolean set(final List<String> keyList, final List<String> valueList) {
    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.set(keyList.get(i), valueList.get(i));
            }
            transaction.exec();
            return true;
        }
    });
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction)

Example 95 with Transaction

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

the class TransactionCommandsTest method discard.

@Test
public void discard() {
    Transaction t = jedis.multi();
    String status = t.discard();
    assertEquals("OK", status);
}
Also used : Transaction(redis.clients.jedis.Transaction) Test(org.junit.Test)

Aggregations

Transaction (redis.clients.jedis.Transaction)149 Test (org.junit.Test)90 Jedis (redis.clients.jedis.Jedis)57 JedisDataException (redis.clients.jedis.exceptions.JedisDataException)15 Set (java.util.Set)14 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)8 List (java.util.List)8 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)7 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)6 Protocol (redis.clients.jedis.Protocol)4 Response (redis.clients.jedis.Response)4 JedisException (redis.clients.jedis.exceptions.JedisException)4 Header (redis.clients.jedis.graph.Header)4 Record (redis.clients.jedis.graph.Record)4 ResultSet (redis.clients.jedis.graph.ResultSet)4 Node (redis.clients.jedis.graph.entities.Node)4 Property (redis.clients.jedis.graph.entities.Property)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3