Search in sources :

Example 56 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project blog by liqianggh.

the class RedisShardedPoolUtil method setNx.

// setNx方法
public static Long setNx(String key, String value) {
    ShardedJedis jedis = null;
    Long result = null;
    try {
        jedis = RedisShardedPool.getJedis();
        result = jedis.setnx(key, value);
    } catch (Exception e) {
        log.error("set key:{} value:{} error", key, value, e);
        RedisShardedPool.returnBrokenResource(jedis);
        return result;
    }
    RedisShardedPool.returnResource(jedis);
    return result;
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis)

Example 57 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project blog by liqianggh.

the class RedisShardedPoolUtil method set.

// set方法
public static String set(String key, String value) {
    ShardedJedis jedis = null;
    String result = null;
    try {
        jedis = RedisShardedPool.getJedis();
        result = jedis.set(key, value);
    } catch (Exception e) {
        log.error("set key:{} value:{} error", key, value, e);
        RedisShardedPool.returnBrokenResource(jedis);
        return result;
    }
    RedisShardedPool.returnResource(jedis);
    return result;
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis)

Example 58 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project blog by liqianggh.

the class RedisShardedPoolUtil method sismember.

// sismember 方法
public static Boolean sismember(String key, String member) {
    ShardedJedis jedis = null;
    Boolean result = false;
    try {
        jedis = RedisShardedPool.getJedis();
        result = jedis.sismember(key, member);
    } catch (Exception e) {
        log.error("sismember key:{} error", key, e);
        RedisShardedPool.returnBrokenResource(jedis);
        return result;
    }
    RedisShardedPool.returnResource(jedis);
    return result;
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis)

Example 59 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project blog by liqianggh.

the class RedisShardedPoolUtil method sadd.

// sadd方法
public static Long sadd(String key, String value, Integer expireTime) {
    ShardedJedis jedis = null;
    Long result = null;
    if (expireTime == null) {
        expireTime = 60 * 30;
    }
    try {
        jedis = RedisShardedPool.getJedis();
        result = jedis.sadd(key, value);
        jedis.expire(key, Const.CacheTime.VIEW_COUNT_TIME);
    } catch (Exception e) {
        log.error("sadd key:{} value:{} error", key, value, e);
        RedisShardedPool.returnBrokenResource(jedis);
    }
    RedisShardedPool.returnResource(jedis);
    return result;
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis)

Example 60 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project blog by liqianggh.

the class RedisShardedPoolUtil method hdel.

// hdel
public static Long hdel(String key, String filed) {
    ShardedJedis jedis = null;
    Long result = null;
    try {
        jedis = RedisShardedPool.getJedis();
        result = jedis.hdel(key, filed);
    } catch (Exception e) {
        log.error("hget key:{} filed:{} error{}", key, filed, e);
        RedisShardedPool.returnBrokenResource(jedis);
    }
    RedisShardedPool.returnResource(jedis);
    return result;
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis)

Aggregations

ShardedJedis (redis.clients.jedis.ShardedJedis)83 Test (org.junit.Test)56 JedisShardInfo (redis.clients.jedis.JedisShardInfo)36 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)35 ArrayList (java.util.ArrayList)33 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)33 Jedis (redis.clients.jedis.Jedis)21 URI (java.net.URI)6 ShardedJedisPipeline (redis.clients.jedis.ShardedJedisPipeline)6 Before (org.junit.Before)3 Serializable (java.io.Serializable)2 BinaryShardedJedis (redis.clients.jedis.BinaryShardedJedis)2 JedisException (redis.clients.jedis.exceptions.JedisException)1