use of redis.clients.jedis.Transaction in project cachecloud by sohutv.
the class TransactionCommandsTest method select.
@Test
public void select() {
jedis.select(1);
jedis.set("foo", "bar");
jedis.watch("foo");
Transaction t = jedis.multi();
t.select(0);
t.set("bar", "foo");
Jedis jedis2 = createJedis();
jedis2.select(1);
jedis2.set("foo", "bar2");
List<Object> results = t.exec();
assertNull(results);
}
use of redis.clients.jedis.Transaction in project cachecloud by sohutv.
the class TransactionCommandsTest method unwatch.
@Test
public void unwatch() throws UnknownHostException, IOException {
jedis.watch("mykey");
String val = jedis.get("mykey");
val = "foo";
String status = jedis.unwatch();
assertEquals("OK", status);
Transaction t = jedis.multi();
nj.connect();
nj.auth("foobared");
nj.set("mykey", "bar");
nj.disconnect();
t.set("mykey", val);
List<Object> resp = t.exec();
assertEquals(1, resp.size());
assertEquals("OK", resp.get(0));
// Binary
jedis.watch(bmykey);
byte[] bval = jedis.get(bmykey);
bval = bfoo;
status = jedis.unwatch();
assertEquals(Keyword.OK.name(), status);
t = jedis.multi();
nj.connect();
nj.auth("foobared");
nj.set(bmykey, bbar);
nj.disconnect();
t.set(bmykey, bval);
resp = t.exec();
assertEquals(1, resp.size());
assertEquals("OK", resp.get(0));
}
use of redis.clients.jedis.Transaction in project gitblit by gitblit.
the class RedisTicketService method deleteTicketImpl.
/**
* Deletes a ticket.
*
* @param ticket
* @return true if successful
*/
@Override
protected boolean deleteTicketImpl(RepositoryModel repository, TicketModel ticket, String deletedBy) {
boolean success = false;
if (ticket == null) {
throw new RuntimeException("must specify a ticket!");
}
Jedis jedis = pool.getResource();
if (jedis == null) {
return false;
}
try {
// atomically remove ticket
Transaction t = jedis.multi();
t.del(key(repository, KeyType.ticket, ticket.number));
t.del(key(repository, KeyType.journal, ticket.number));
t.exec();
success = true;
log.debug("deleted ticket {} from Redis @ {}", "" + ticket.number, getUrl());
} catch (JedisException e) {
log.error("failed to delete ticket from 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 gitblit by gitblit.
the class RedisTicketService method commitChangeImpl.
/**
* Commit a ticket change to the repository.
*
* @param repository
* @param ticketId
* @param change
* @return true, if the change was committed
*/
@Override
protected boolean commitChangeImpl(RepositoryModel repository, long ticketId, Change change) {
Jedis jedis = pool.getResource();
if (jedis == null) {
return false;
}
try {
List<Change> changes = getJournal(jedis, repository, ticketId);
changes.add(change);
// build a new effective ticket from the changes
TicketModel ticket = TicketModel.buildTicket(changes);
String object = TicketSerializer.serialize(ticket);
String journal = TicketSerializer.serialize(change);
// atomically store ticket
Transaction t = jedis.multi();
t.set(key(repository, KeyType.ticket, ticketId), object);
t.rpush(key(repository, KeyType.journal, ticketId), journal);
t.exec();
log.debug("updated ticket {} in Redis @ {}", "" + ticketId, getUrl());
return true;
} catch (JedisException e) {
log.error("failed to update ticket cache in Redis @ " + getUrl(), e);
pool.returnBrokenResource(jedis);
jedis = null;
} finally {
if (jedis != null) {
pool.returnResource(jedis);
}
}
return false;
}
use of redis.clients.jedis.Transaction in project gitblit by gitblit.
the class RedisTicketService method deleteAllImpl.
/**
* Deletes all Tickets for the rpeository from the Redis key-value store.
*
*/
@Override
protected boolean deleteAllImpl(RepositoryModel repository) {
Jedis jedis = pool.getResource();
if (jedis == null) {
return false;
}
boolean success = false;
try {
Set<String> keys = jedis.keys(repository.name + ":*");
if (keys.size() > 0) {
Transaction t = jedis.multi();
t.del(keys.toArray(new String[keys.size()]));
t.exec();
}
success = true;
} catch (JedisException e) {
log.error("failed to delete all tickets in Redis @ " + getUrl(), e);
pool.returnBrokenResource(jedis);
jedis = null;
} finally {
if (jedis != null) {
pool.returnResource(jedis);
}
}
return success;
}
Aggregations