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