Search in sources :

Example 86 with JedisPool

use of redis.clients.jedis.JedisPool in project warn-report by saaavsaaa.

the class JRedisPool method buildRedisPool.

private void buildRedisPool() {
    properties = new RedisProperties();
    try {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(properties.getMaxTotal());
        config.setMaxIdle(properties.getMaxIdle());
        config.setMaxWaitMillis(properties.getMaxWait());
        // 在获取连接的时候检查有效性, 默认false
        config.setTestOnBorrow(properties.isTestOnBorrow());
        // 在空闲时检查有效性, 默认false
        config.setTestWhileIdle(properties.isTestWhileIdle());
        jedisPool = new JedisPool(config, properties.getIp(), properties.getPort(), properties.getTimeout(), properties.getAuth());
    } catch (Exception e) {
        System.out.println("case : new JedisPoolConfig or JedisPool error, detail : " + e.getMessage());
    }
}
Also used : JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Example 87 with JedisPool

use of redis.clients.jedis.JedisPool in project tech by ffyyhh995511.

the class JedisService method lpush.

/*##################################################  列表(List) 命令   ######################################################################*/
/**
 * list 左存储
 * @param key
 * @param value
 * @return
 */
public long lpush(String key, String value) {
    long rs = 0;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.lpush(key, value);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
    return rs;
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool)

Example 88 with JedisPool

use of redis.clients.jedis.JedisPool in project tech by ffyyhh995511.

the class JedisService method zadd.

/*##########################  有序集合(sorted set) 命令   ##########################  */
/**
 * 排序集合
 * @param key
 * @param score
 * @param member
 * @return
 */
public long zadd(String key, double score, String member) {
    long rs = 0;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.zadd(key, score, member);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
    return rs;
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool)

Example 89 with JedisPool

use of redis.clients.jedis.JedisPool in project tech by ffyyhh995511.

the class JedisService method hvals.

/**
 * 返回哈希的值(values)
 * @param key
 * @return
 */
public List<String> hvals(String key) {
    List<String> rs = null;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.hvals(key);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
    return rs;
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool)

Example 90 with JedisPool

use of redis.clients.jedis.JedisPool in project tech by ffyyhh995511.

the class JedisService method del.

/**
 * 字符串删除
 * @param key
 */
public long del(String... key) {
    long rs = 0;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.del(key);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
    return rs;
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool)

Aggregations

JedisPool (redis.clients.jedis.JedisPool)108 Jedis (redis.clients.jedis.Jedis)75 Test (org.junit.Test)47 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)40 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)17 HostAndPort (redis.clients.jedis.HostAndPort)6 URI (java.net.URI)5 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)5 JedisCluster (redis.clients.jedis.JedisCluster)5 RpcException (com.alibaba.dubbo.rpc.RpcException)4 URISyntaxException (java.net.URISyntaxException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 JedisException (redis.clients.jedis.exceptions.JedisException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 InvalidURIException (redis.clients.jedis.exceptions.InvalidURIException)3 ArrayList (java.util.ArrayList)2