Skip to content

Commit

Permalink
use condition properly fix apache#1917
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyHZM committed Dec 28, 2018
1 parent 5ea4fa5 commit f18fc1c
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dubbo.registry.redis;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
Expand All @@ -27,8 +28,6 @@
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.support.FailbackRegistry;
import org.apache.dubbo.rpc.RpcException;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPubSub;
Expand All @@ -53,7 +52,6 @@

/**
* RedisRegistry
*
*/
public class RedisRegistry extends FailbackRegistry {

Expand Down Expand Up @@ -589,7 +587,7 @@ public void run() {
try {
if (service.endsWith(Constants.ANY_VALUE)) {
if (!first) {
first = false;
first = true;
Set<String> keys = jedis.keys(service);
if (keys != null && !keys.isEmpty()) {
for (String s : keys) {
Expand All @@ -601,7 +599,7 @@ public void run() {
jedis.psubscribe(new NotifySub(jedisPool), service); // blocking
} else {
if (!first) {
first = false;
first = true;
doNotify(jedis, service);
resetSkip();
}
Expand All @@ -612,6 +610,7 @@ public void run() {
jedis.close();
}
} catch (Throwable t) { // Retry another server
first = false;
logger.warn("Failed to subscribe service from redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
// If you only have a single redis, you need to take a rest to avoid overtaking a lot of CPU resources
sleep(reconnectPeriod);
Expand Down

0 comments on commit f18fc1c

Please sign in to comment.