Search in sources :

Example 91 with JedisPool

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

the class JedisService method flushAll.

/**
 * 删除所有数据库的所有key
 * @return
 */
public String flushAll() {
    String rs = null;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.flushAll();
        }
    } 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 92 with JedisPool

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

the class JedisService method sismember.

/**
 * 判断member 是否是存在key集合(set)中
 * @param key
 * @param member
 * @return
 */
public Boolean sismember(String key, String member) {
    Boolean rs = null;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.sismember(key, 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 93 with JedisPool

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

the class JedisService method mget.

/**
 * 字符串批量获取
 * @param keys
 * @return
 */
public List<String> mget(String... keys) {
    List<String> rs = null;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.mget(keys);
        }
    } 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 94 with JedisPool

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

the class JedisService method sadd.

/*################## set集合命令(无序) ###################*/
/**
 * set集合存储,一次可以插入多个value
 * @param key
 * @param members
 * @return
 */
public Long sadd(String key, String... members) {
    Long rs = null;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.sadd(key, members);
        }
    } 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 95 with JedisPool

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

the class JedisService method scard.

/**
 * 返回set集合的长度
 * @param key
 * @return
 */
public Long scard(String key) {
    Long rs = null;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.scard(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