Search in sources :

Example 76 with Transaction

use of redis.clients.jedis.Transaction in project vcat by dapete42.

the class MetadataRedisCacheTest method put.

@Test
void put() throws CacheException {
    final Connection connectionMock = mock(Connection.class);
    final Transaction transactionSpy = spy(new Transaction(connectionMock, true));
    doReturn(transactionSpy).when(underTest).newTransaction(any(Connection.class));
    final Metadata metadata = new Metadata("articlepath", "server", Collections.singletonMap(0, "0"), Collections.singletonMap("1", 1));
    final IWiki wiki = new TestWiki("apiUrl");
    underTest.put(wiki, metadata);
    final byte[] keyBytes = underTest.jedisKeyBytes(wiki.getApiUrl());
    verify(transactionSpy).set(eq(keyBytes), eq(SerializationUtils.serialize(metadata)));
    verify(transactionSpy).expire(eq(keyBytes), eq(1000L));
}
Also used : Transaction(redis.clients.jedis.Transaction) IWiki(vcat.mediawiki.IWiki) Connection(redis.clients.jedis.Connection) Metadata(vcat.mediawiki.Metadata) Test(org.junit.jupiter.api.Test)

Example 77 with Transaction

use of redis.clients.jedis.Transaction in project carbon-apimgt by wso2.

the class RedisBaseDistributedCountManager method setExpiry.

@Override
public void setExpiry(String key, long expiryTimeStamp) {
    long startTime = 0;
    try {
        startTime = System.currentTimeMillis();
        try (Jedis jedis = redisPool.getResource()) {
            Transaction transaction = jedis.multi();
            transaction.pexpireAt(key, expiryTimeStamp);
            transaction.exec();
        }
    } finally {
        if (log.isDebugEnabled()) {
            log.debug("Time Taken to setExpiry :" + (System.currentTimeMillis() - startTime));
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction)

Example 78 with Transaction

use of redis.clients.jedis.Transaction in project carbon-apimgt by wso2.

the class RedisBaseDistributedCountManager method asyncGetAndAlterCounter.

@Override
public long asyncGetAndAlterCounter(String key, long value) {
    long startTime = 0;
    try {
        startTime = System.currentTimeMillis();
        try (Jedis jedis = redisPool.getResource()) {
            long current = 0;
            Transaction transaction = jedis.multi();
            Response<String> currentValue = transaction.get(key);
            transaction.del(key);
            Response<Long> incrementedValue = transaction.incrBy(key, value);
            transaction.exec();
            if (currentValue != null) {
                current = Long.parseLong(currentValue.get());
            }
            if (log.isDebugEnabled()) {
                log.info(String.format("%s Key increased from %s to %s", key, current, incrementedValue.get()));
            }
            return current;
        }
    } finally {
        if (log.isDebugEnabled()) {
            log.debug("Time Taken to asyncGetAndAlterDistributedCounter :" + (System.currentTimeMillis() - startTime));
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction)

Example 79 with Transaction

use of redis.clients.jedis.Transaction in project carbon-apimgt by wso2.

the class RedisBaseDistributedCountManager method asyncGetAndAddCounter.

@Override
public long asyncGetAndAddCounter(String key, long value) {
    long startTime = 0;
    try {
        startTime = System.currentTimeMillis();
        try (Jedis jedis = redisPool.getResource()) {
            long current = 0;
            Transaction transaction = jedis.multi();
            Response<String> currentValue = transaction.get(key);
            Response<Long> incrementedValue = transaction.incrBy(key, value);
            transaction.exec();
            if (currentValue != null) {
                current = Long.parseLong(currentValue.get());
            }
            if (log.isDebugEnabled()) {
                log.info(String.format("%s Key increased from %s to %s", key, current, incrementedValue.get()));
            }
            return current;
        }
    } finally {
        if (log.isDebugEnabled()) {
            log.debug("Time Taken to asyncGetAndAddDistributedCounter :" + (System.currentTimeMillis() - startTime));
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction)

Example 80 with Transaction

use of redis.clients.jedis.Transaction in project carbon-apimgt by wso2.

the class RedisBaseDistributedCountManager method removeTimestamp.

@Override
public void removeTimestamp(String key) {
    long startTime = 0;
    try {
        startTime = System.currentTimeMillis();
        try (Jedis jedis = redisPool.getResource()) {
            Transaction transaction = jedis.multi();
            transaction.del(key);
            transaction.exec();
        }
    } finally {
        if (log.isDebugEnabled()) {
            log.debug("Time Taken to removeTimestamp :" + (System.currentTimeMillis() - startTime));
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction)

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