use of redis.clients.jedis.JedisPool in project dubbo by alibaba.
the class RedisRegistry method doSubscribe.
@Override
public void doSubscribe(final URL url, final NotifyListener listener) {
String service = toServicePath(url);
Notifier notifier = notifiers.get(service);
if (notifier == null) {
Notifier newNotifier = new Notifier(service);
notifiers.putIfAbsent(service, newNotifier);
notifier = notifiers.get(service);
if (notifier == newNotifier) {
notifier.start();
}
}
boolean success = false;
RpcException exception = null;
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
Jedis jedis = jedisPool.getResource();
try {
if (service.endsWith(Constants.ANY_VALUE)) {
admin = true;
Set<String> keys = jedis.keys(service);
if (keys != null && !keys.isEmpty()) {
Map<String, Set<String>> serviceKeys = new HashMap<String, Set<String>>();
for (String key : keys) {
String serviceKey = toServicePath(key);
Set<String> sk = serviceKeys.get(serviceKey);
if (sk == null) {
sk = new HashSet<String>();
serviceKeys.put(serviceKey, sk);
}
sk.add(key);
}
for (Set<String> sk : serviceKeys.values()) {
doNotify(jedis, sk, url, Arrays.asList(listener));
}
}
} else {
doNotify(jedis, jedis.keys(service + Constants.PATH_SEPARATOR + Constants.ANY_VALUE), url, Arrays.asList(listener));
}
success = true;
// Just read one server's data
break;
} finally {
jedis.close();
}
} catch (Throwable t) {
// Try the next server
exception = new RpcException("Failed to subscribe service from redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
}
}
if (exception != null) {
if (success) {
logger.warn(exception.getMessage(), exception);
} else {
throw exception;
}
}
}
use of redis.clients.jedis.JedisPool in project tech by ffyyhh995511.
the class JedisService method smembers.
/**
* 返回set集合 values 数据
* @param key
* @return
*/
public Set<String> smembers(String key) {
Set<String> rs = null;
Jedis jedis = null;
JedisPool jedisPool = null;
try {
jedisPool = getJedisPool();
jedis = jedisPool.getResource();
if (jedis != null) {
rs = jedis.smembers(key);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (jedis != null) {
jedis.close();
}
}
return rs;
}
use of redis.clients.jedis.JedisPool in project tech by ffyyhh995511.
the class JedisService method hlen.
/**
* 哈希长度
* @param key
* @return
*/
public Long hlen(String key) {
Long rs = null;
Jedis jedis = null;
JedisPool jedisPool = null;
try {
jedisPool = getJedisPool();
jedis = jedisPool.getResource();
if (jedis != null) {
rs = jedis.hlen(key);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (jedis != null) {
jedis.close();
}
}
return rs;
}
use of redis.clients.jedis.JedisPool in project tech by ffyyhh995511.
the class JedisService method dbSize.
/**
* 返回当前选中数据库中键的数量
* @return
*/
public long dbSize() {
long rs = 0;
Jedis jedis = null;
JedisPool jedisPool = null;
try {
jedisPool = getJedisPool();
jedis = jedisPool.getResource();
if (jedis != null) {
rs = jedis.dbSize();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (jedis != null) {
jedis.close();
}
}
return rs;
}
use of redis.clients.jedis.JedisPool in project tech by ffyyhh995511.
the class JedisService method zrange.
/**
* 返回排序集合
* @param key
* @param start
* @param end
* @return
*/
public Set<String> zrange(String key, long start, long end) {
Set<String> rs = null;
Jedis jedis = null;
JedisPool jedisPool = null;
try {
jedisPool = getJedisPool();
jedis = jedisPool.getResource();
if (jedis != null) {
rs = jedis.zrange(key, start, end);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (jedis != null) {
jedis.close();
}
}
return rs;
}
Aggregations