Search in sources :

Example 36 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project jedis by xetorthio.

the class Pipeline method exec.

public Response<List<Object>> exec() {
    if (currentMulti == null)
        throw new JedisDataException("EXEC without MULTI");
    client.exec();
    Response<List<Object>> response = super.getResponse(currentMulti);
    currentMulti.setResponseDependency(response);
    currentMulti = null;
    return response;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) JedisDataException(redis.clients.jedis.exceptions.JedisDataException)

Example 37 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project jedis by xetorthio.

the class Pipeline method multi.

public Response<String> multi() {
    if (currentMulti != null)
        throw new JedisDataException("MULTI calls can not be nested");
    client.multi();
    // Expecting
    Response<String> response = getResponse(BuilderFactory.STRING);
    // OK
    currentMulti = new MultiResponseBuilder();
    return response;
}
Also used : JedisDataException(redis.clients.jedis.exceptions.JedisDataException)

Example 38 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project geode by apache.

the class AuthJUnitTest method testAuthAcceptRequests.

@Test
public void testAuthAcceptRequests() {
    setupCacheWithPassword();
    Exception ex = null;
    try {
        jedis.set("foo", "bar");
    } catch (JedisDataException e) {
        ex = e;
    }
    assertNotNull(ex);
    String res = jedis.auth(PASSWORD);
    assertEquals(res, "OK");
    // No exception
    jedis.set("foo", "bar");
}
Also used : JedisDataException(redis.clients.jedis.exceptions.JedisDataException) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) IOException(java.io.IOException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 39 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project ignite by apache.

the class RedisProtocolSelfTest method testGet.

/**
     * @throws Exception If failed.
     */
public void testGet() throws Exception {
    try (Jedis jedis = pool.getResource()) {
        jcache().put("getKey1", "getVal1");
        Assert.assertEquals("getVal1", jedis.get("getKey1"));
        Assert.assertNull(jedis.get("wrongKey"));
        jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
        try {
            jedis.get("setDataTypeKey");
            assert false : "Exception has to be thrown!";
        } catch (JedisDataException e) {
            assertTrue(e.getMessage().startsWith("WRONGTYPE"));
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisDataException(redis.clients.jedis.exceptions.JedisDataException)

Example 40 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project ignite by apache.

the class RedisProtocolSelfTest method testIncrDecr.

/**
     * @throws Exception If failed.
     */
public void testIncrDecr() throws Exception {
    try (Jedis jedis = pool.getResource()) {
        Assert.assertEquals(1, (long) jedis.incr("newKeyIncr"));
        Assert.assertEquals(-1, (long) jedis.decr("newKeyDecr"));
        Assert.assertEquals("1", jedis.get("newKeyIncr"));
        Assert.assertEquals("-1", jedis.get("newKeyDecr"));
        Assert.assertEquals(1, (long) jedis.incr("incrKey1"));
        jedis.set("incrKey1", "10");
        Assert.assertEquals(11L, (long) jedis.incr("incrKey1"));
        jedis.set("decrKey1", "10");
        Assert.assertEquals(9L, (long) jedis.decr("decrKey1"));
        jedis.set("nonInt", "abc");
        try {
            jedis.incr("nonInt");
            assert false : "Exception has to be thrown!";
        } catch (JedisDataException e) {
            assertTrue(e.getMessage().startsWith("ERR"));
        }
        try {
            jedis.decr("nonInt");
            assert false : "Exception has to be thrown!";
        } catch (JedisDataException e) {
            assertTrue(e.getMessage().startsWith("ERR"));
        }
        jedis.set("outOfRangeIncr1", "9223372036854775808");
        try {
            jedis.incr("outOfRangeIncr1");
            assert false : "Exception has to be thrown!";
        } catch (JedisDataException e) {
            assertTrue(e.getMessage().startsWith("ERR"));
        }
        jedis.set("outOfRangeDecr1", "-9223372036854775809");
        try {
            jedis.decr("outOfRangeDecr1");
            assert false : "Exception has to be thrown!";
        } catch (JedisDataException e) {
            assertTrue(e.getMessage().startsWith("ERR"));
        }
        jedis.set("outOfRangeInc2", String.valueOf(Long.MAX_VALUE));
        try {
            jedis.incr("outOfRangeInc2");
            assert false : "Exception has to be thrown!";
        } catch (JedisDataException e) {
            assertTrue(e.getMessage().startsWith("ERR"));
        }
        jedis.set("outOfRangeDecr2", String.valueOf(Long.MIN_VALUE));
        try {
            jedis.decr("outOfRangeDecr2");
            assert false : "Exception has to be thrown!";
        } catch (JedisDataException e) {
            assertTrue(e.getMessage().startsWith("ERR"));
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisDataException(redis.clients.jedis.exceptions.JedisDataException)

Aggregations

JedisDataException (redis.clients.jedis.exceptions.JedisDataException)46 Jedis (redis.clients.jedis.Jedis)27 Test (org.junit.Test)20 Pipeline (redis.clients.jedis.Pipeline)6 Transaction (redis.clients.jedis.Transaction)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)4 List (java.util.List)3 Set (java.util.Set)3 Logger (org.apache.log4j.Logger)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Response (redis.clients.jedis.Response)2 QueryRedisClusterDetailResponse (beans.response.QueryRedisClusterDetailResponse)1 ObjectInput (com.alibaba.dubbo.common.serialize.ObjectInput)1 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)1 Invocation (com.alibaba.dubbo.rpc.Invocation)1 RpcException (com.alibaba.dubbo.rpc.RpcException)1