Search in sources :

Example 61 with ShardedJedis

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

the class RedisShardedPoolUtil method get.

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

Example 62 with ShardedJedis

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

the class RedisShardedPoolUtil method hset.

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

Example 63 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project jeesuite-libs by vakinge.

the class JedisShardProvider method release.

public void release() {
    ShardedJedis jedis = context.get();
    if (jedis != null) {
        context.remove();
        jedis.close();
        if (logger.isTraceEnabled()) {
            logger.trace("<<release a redis conn[{}]", jedis.toString());
        }
    }
}
Also used : BinaryShardedJedis(redis.clients.jedis.BinaryShardedJedis) ShardedJedis(redis.clients.jedis.ShardedJedis)

Example 64 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project new-cloud by xie-summer.

the class ShardedJedisPipelineTest method setUp.

@Before
public void setUp() throws Exception {
    Jedis jedis = new Jedis(redis1.getHost(), redis1.getPort());
    jedis.auth("foobared");
    jedis.flushAll();
    jedis.disconnect();
    jedis = new Jedis(redis2.getHost(), redis2.getPort());
    jedis.auth("foobared");
    jedis.flushAll();
    jedis.disconnect();
    JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.getHost(), redis1.getPort());
    JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.getHost(), redis2.getPort());
    shardInfo1.setPassword("foobared");
    shardInfo2.setPassword("foobared");
    List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
    shards.add(shardInfo1);
    shards.add(shardInfo2);
    this.jedis = new ShardedJedis(shards);
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) ShardedJedis(redis.clients.jedis.ShardedJedis) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Before(org.junit.Before)

Example 65 with ShardedJedis

use of redis.clients.jedis.ShardedJedis in project new-cloud by xie-summer.

the class ShardedJedisPoolTest method checkPoolOverflow.

@Test(expected = JedisConnectionException.class)
public void checkPoolOverflow() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(1);
    config.setBlockWhenExhausted(false);
    ShardedJedisPool pool = new ShardedJedisPool(config, shards);
    ShardedJedis jedis = pool.getResource();
    jedis.set("foo", "0");
    ShardedJedis newJedis = pool.getResource();
    newJedis.incr("foo");
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedis(redis.clients.jedis.ShardedJedis) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) Test(org.junit.Test)

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