use of redis.clients.jedis.Transaction in project jedis by xetorthio.
the class TransactionCommandsTest method watch.
@Test
public void watch() throws UnknownHostException, IOException {
jedis.watch("mykey", "somekey");
Transaction t = jedis.multi();
nj.connect();
nj.auth("foobared");
nj.set("mykey", "bar");
nj.disconnect();
t.set("mykey", "foo");
List<Object> resp = t.exec();
assertEquals(null, resp);
assertEquals("bar", jedis.get("mykey"));
// Binary
jedis.watch(bmykey, "foobar".getBytes());
t = jedis.multi();
nj.connect();
nj.auth("foobared");
nj.set(bmykey, bbar);
nj.disconnect();
t.set(bmykey, bfoo);
resp = t.exec();
assertEquals(null, resp);
assertTrue(Arrays.equals(bbar, jedis.get(bmykey)));
}
use of redis.clients.jedis.Transaction in project jedis by xetorthio.
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 jedis by xetorthio.
the class TransactionCommandsTest method testResetStateWhenInMulti.
@Test
public void testResetStateWhenInMulti() {
jedis.auth("foobared");
Transaction t = jedis.multi();
t.set("foooo", "barrr");
jedis.resetState();
assertEquals(null, jedis.get("foooo"));
}
use of redis.clients.jedis.Transaction in project cachecloud by sohutv.
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());
}
use of redis.clients.jedis.Transaction in project cachecloud by sohutv.
the class JedisSentinelPoolTest method returnResourceShouldResetState.
@Test
public void returnResourceShouldResetState() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000, "foobared", 2);
Jedis jedis = pool.getResource();
Jedis jedis2 = null;
try {
jedis.set("hello", "jedis");
Transaction t = jedis.multi();
t.set("hello", "world");
jedis.close();
jedis2 = pool.getResource();
assertTrue(jedis == jedis2);
assertEquals("jedis", jedis2.get("hello"));
} catch (JedisConnectionException e) {
if (jedis2 != null) {
jedis2 = null;
}
} finally {
jedis2.close();
pool.destroy();
}
}
Aggregations