Search in sources :

Example 96 with JedisPool

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

the class JedisService method set.

/*############################################  字符串(String) 命令  ######################################*/
/**
 * 字符串存储
 * @param key
 * @param value
 * @return
 */
public String set(String key, String value) {
    String rs = null;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.set(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 97 with JedisPool

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

the class JedisService method hget.

/**
 * 哈希获取
 * @param key
 * @param field
 * @return
 */
public String hget(String key, String field) {
    String rs = null;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.hget(key, field);
        }
    } 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 98 with JedisPool

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

the class JedisService method get.

public String get(String key) {
    String rs = null;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.get(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 99 with JedisPool

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

the class JedisService method hdel.

/**
 * 哈希删除多个域
 * @param key
 * @param fields
 * @return
 */
public long hdel(String key, String... fields) {
    long rs = 0;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.hdel(key, fields);
        }
    } 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 100 with JedisPool

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

the class JedisService method zrem.

/**
 * 有序列表删除
 * @param key
 * @param members
 * @return
 */
public long zrem(String key, String... members) {
    long rs = 0;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.zrem(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)

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