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));
}
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));
}
}
}
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));
}
}
}
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));
}
}
}
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));
}
}
}
Aggregations