use of redis.clients.jedis.ShardedJedis in project tech by ffyyhh995511.
the class JedisShardService method set.
public String set(String key, String value) {
ShardedJedis shardedJedis = pool.getResource();
String rs = shardedJedis.set(key, value);
shardedJedis.close();
return rs;
}
use of redis.clients.jedis.ShardedJedis in project oxCore by GluuFederation.
the class RedisShardedProvider method get.
@Override
public Object get(String key) {
ShardedJedis jedis = pool.getResource();
try {
byte[] value = jedis.get(key.getBytes());
Object deserialized = null;
if (value != null && value.length > 0) {
deserialized = SerializationUtils.deserialize(value);
}
return deserialized;
} finally {
jedis.close();
}
}
use of redis.clients.jedis.ShardedJedis in project java-example by 1479005017.
the class RedisPoolTest method testShare2.
@Test
public void testShare2() throws Exception {
ShardedJedisPool jedisPool = RedisConfig.getSharedPool();
ShardedJedis jedis = jedisPool.getResource();
System.out.println(String.format("name1: %s", jedis.get("name1")));
System.out.println(String.format("name2: %s", jedis.get("name2")));
System.out.println(String.format("name3: %s", jedis.get("name3")));
System.out.println(String.format("name4: %s", jedis.get("name4")));
Thread.sleep(10 * 1000);
// 抛出 JedisException: Could not get a resource from the pool
System.out.println("sleep 10 seconds, and shutdown one redis");
System.out.println(String.format("name1: %s", jedis.get("name1")));
System.out.println(String.format("name2: %s", jedis.get("name2")));
System.out.println(String.format("name3: %s", jedis.get("name3")));
System.out.println(String.format("name4: %s", jedis.get("name4")));
jedis.close();
}
use of redis.clients.jedis.ShardedJedis in project blog by liqianggh.
the class RedisShardedPoolUtil method del.
// 设置有效期 单位是秒
public static Long del(String key) {
ShardedJedis jedis = null;
Long result = null;
try {
jedis = RedisShardedPool.getJedis();
result = jedis.del(key);
} catch (Exception e) {
log.error("del 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 setEx.
// 设置过期时间 秒
public static String setEx(String key, String value, int exTime) {
ShardedJedis jedis = null;
String result = null;
try {
jedis = RedisShardedPool.getJedis();
result = jedis.setex(key, exTime, value);
} catch (Exception e) {
log.error("setex:{} value:{} exTime{} error", key, value, exTime, e);
RedisShardedPool.returnBrokenResource(jedis);
return result;
}
RedisShardedPool.returnResource(jedis);
return result;
}
Aggregations