Search in sources :

Example 41 with JedisDataException

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

the class RedisProtocolSelfTest method testStrlen.

/**
     * @throws Exception If failed.
     */
public void testStrlen() throws Exception {
    try (Jedis jedis = pool.getResource()) {
        Assert.assertEquals(0, (long) jedis.strlen("strlenKeyNonExisting"));
        jcache().put("strlenKey", "abc");
        Assert.assertEquals(3, (long) jedis.strlen("strlenKey"));
        jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
        try {
            jedis.strlen("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 42 with JedisDataException

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

the class RedisProtocolStringSelfTest 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)

Example 43 with JedisDataException

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

the class RedisProtocolStringSelfTest 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 44 with JedisDataException

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

the class RedisProtocolStringSelfTest method testIncrDecrBy.

/**
 * @throws Exception If failed.
 */
public void testIncrDecrBy() throws Exception {
    try (Jedis jedis = pool.getResource()) {
        Assert.assertEquals(2, (long) jedis.incrBy("newKeyIncrBy", 2));
        Assert.assertEquals(-2, (long) jedis.decrBy("newKeyDecrBy", 2));
        jedis.set("incrDecrKeyBy", "1");
        Assert.assertEquals(11L, (long) jedis.incrBy("incrDecrKeyBy", 10));
        Assert.assertEquals(9L, (long) jedis.decrBy("incrDecrKeyBy", 2));
        jedis.set("outOfRangeIncrBy", "1");
        try {
            jedis.incrBy("outOfRangeIncrBy", Long.MAX_VALUE);
            assert false : "Exception has to be thrown!";
        } catch (JedisDataException e) {
            assertTrue(e.getMessage().startsWith("ERR"));
        }
        jedis.set("outOfRangeDecrBy", "-1");
        try {
            jedis.decrBy("outOfRangeDecrBy", Long.MIN_VALUE);
            assert false : "Exception has to be thrown!";
        } catch (JedisDataException e) {
            assertTrue(e.getMessage().startsWith("ERR"));
        }
        jedis.set("outOfRangeIncBy2", String.valueOf(Long.MAX_VALUE));
        try {
            jedis.incrBy("outOfRangeIncBy2", Long.MAX_VALUE);
            assert false : "Exception has to be thrown!";
        } catch (JedisDataException e) {
            assertTrue(e.getMessage().startsWith("ERR"));
        }
        jedis.set("outOfRangeDecrBy2", String.valueOf(Long.MIN_VALUE));
        try {
            jedis.decrBy("outOfRangeDecrBy2", Long.MIN_VALUE);
            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)

Example 45 with JedisDataException

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

the class RedisProtocolStringSelfTest method testAppend.

/**
 * @throws Exception If failed.
 */
public void testAppend() throws Exception {
    try (Jedis jedis = pool.getResource()) {
        Assert.assertEquals(5, (long) jedis.append("appendKey1", "Hello"));
        Assert.assertEquals(12, (long) jedis.append("appendKey1", " World!"));
        jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
        try {
            jedis.append("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)

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