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;
}
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;
}
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());
}
}
}
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);
}
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");
}
Aggregations