redis.clients.jedis.BinaryJedisPubSub Java Examples

The following examples show how to use redis.clients.jedis.BinaryJedisPubSub. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisPubSubSync.java    From smart-cache with Apache License 2.0 6 votes vote down vote up
public RedisPubSubSync(final CacheTemplate cacheTemplate) {
    this.cacheTemplate = cacheTemplate;
    this.cacheSyncHandler = new CacheSyncHandler(this.cacheTemplate);
    this.jedisTemplate = cacheTemplate.getJedisTemplate();

    new Thread(new Runnable() {
        @Override
        public void run() {
            jedisTemplate.subscribe(new BinaryJedisPubSub() {
                @Override
                public void onMessage(byte[] channel, byte[] message) {
                    Command cmd = jedisTemplate.deserializeVal(message);
                    if (cmd != null) {
                        if ((cmd.src != null && !cmd.src.equals(Cache.ID)) || cmd.oper == Command.OPT_FETCH) {
                            logger.debug("recieve from " + cmd.src + " > " + cmd.toString());
                            cacheSyncHandler.handle(cmd);
                        }
                    }
                }
            }, Cache.CACHE_STORE_SYNC);
        }
    }, "RedisPubSubSync.Subscribe").start();
}
 
Example #2
Source File: JbootEhredisCacheImpl.java    From jboot with Apache License 2.0 6 votes vote down vote up
public JbootEhredisCacheImpl() {
    this.ehcacheImpl = new JbootEhcacheImpl();
    this.ehcacheImpl.setCacheEventListener(this);

    this.redisCacheImpl = new JbootRedisCacheImpl();
    this.clientId = StrUtil.uuid();
    this.serializer = Jboot.getSerializer();

    this.redis = redisCacheImpl.getRedis();
    this.redis.subscribe(new BinaryJedisPubSub() {
        @Override
        public void onMessage(byte[] channel, byte[] message) {
            JbootEhredisCacheImpl.this.onMessage((String) serializer.deserialize(channel), serializer.deserialize(message));
        }
    }, serializer.serialize(channel));
}
 
Example #3
Source File: EnhancedJedisCluster.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public void psubscribe(final BinaryJedisPubSub jedisPubSub, final byte[]... patterns) {
	new EnhancedJedisClusterCommand<Integer>(connectionHandler, maxAttempts) {
		@Override
		public Integer doExecute(Jedis connection) {
			connection.psubscribe(jedisPubSub, patterns);
			return 0;
		}
	}.runWithAnyNode();
}
 
Example #4
Source File: JedisAdapter.java    From gameserver with Apache License 2.0 5 votes vote down vote up
@Override
public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) {
	redis.clients.jedis.Jedis delegate = pool.getResource();
	try {
		delegate.psubscribe(jedisPubSub, patterns);
	} finally {
		pool.returnResource(delegate);
	}
}
 
Example #5
Source File: JedisAdapter.java    From gameserver with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels) {
	redis.clients.jedis.Jedis delegate = pool.getResource();
	try {
		delegate.subscribe(jedisPubSub, channels);
	} finally {
		pool.returnResource(delegate);
	}
}
 
Example #6
Source File: TestJedisClusterFacade.java    From HttpSessionReplacer with MIT License 5 votes vote down vote up
@Test
public void testPsubscribe() {
  BinaryJedisPubSub listener = mock(BinaryJedisPubSub.class);
  RedisFacade.RedisPubSub facadeListener = mock(RedisFacade.RedisPubSub.class);
  when(facadeListener.getLinked()).thenReturn(listener);
  String pattern = "test";
  rf.psubscribe(facadeListener, pattern);
  ArgumentCaptor<BinaryJedisPubSub> capture = ArgumentCaptor.forClass(BinaryJedisPubSub.class);
  verify(facadeListener).link(capture.capture());
  verify(jedisCluster).psubscribe(capture.getValue(), SafeEncoder.encode(pattern));
}
 
Example #7
Source File: TestJedisPoolFacade.java    From HttpSessionReplacer with MIT License 5 votes vote down vote up
@Test
public void testPsubscribe() {
  BinaryJedisPubSub listener = mock(BinaryJedisPubSub.class);
  RedisFacade.RedisPubSub facadeListener = mock(RedisFacade.RedisPubSub.class);
  when(facadeListener.getLinked()).thenReturn(listener);
  String pattern = "test";
  rf.psubscribe(facadeListener, pattern);
  ArgumentCaptor<BinaryJedisPubSub> capture = ArgumentCaptor.forClass(BinaryJedisPubSub.class);
  verify(facadeListener).link(capture.capture());
  verify(jedis).psubscribe(capture.getValue(), SafeEncoder.encode(pattern));
}
 
Example #8
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) {
  Span span = helper.buildSpan("psubscribe");
  span.setTag("patterns", Arrays.toString(patterns));
  try {
    super.psubscribe(jedisPubSub, patterns);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #9
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels) {
  Span span = helper.buildSpan("subscribe");
  span.setTag("channels", Arrays.toString(channels));
  try {
    super.subscribe(jedisPubSub, channels);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #10
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) {
  Span span = helper.buildSpan("psubscribe");
  span.setTag("patterns", Arrays.toString(patterns));
  try {
    super.psubscribe(jedisPubSub, patterns);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #11
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels) {
  Span span = helper.buildSpan("subscribe");
  span.setTag("channels", Arrays.toString(channels));
  try {
    super.subscribe(jedisPubSub, channels);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #12
Source File: JbootRedismqImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
protected void onStartListening() {

    String[] channels = this.channels.toArray(new String[]{});

    redis.subscribe(new BinaryJedisPubSub() {
        @Override
        public void onMessage(byte[] channel, byte[] message) {
            notifyListeners(redis.bytesToKey(channel), getSerializer().deserialize(message));
        }
    }, redis.keysToBytesArray(channels));

    dequeueThread = new Thread(this,"redis-dequeue-thread");
    dequeueThread.start();
}
 
Example #13
Source File: EnhancedJedisCluster.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(final BinaryJedisPubSub jedisPubSub, final byte[]... channels) {
	new EnhancedJedisClusterCommand<Integer>(connectionHandler, maxAttempts) {
		@Override
		public Integer doExecute(Jedis connection) {
			connection.subscribe(jedisPubSub, channels);
			return 0;
		}
	}.runWithAnyNode();
}
 
Example #14
Source File: JedisTemplate.java    From smart-cache with Apache License 2.0 5 votes vote down vote up
public void subscribe(final BinaryJedisPubSub jedisPubSub, final String... channels) {
    if (cluster) {
        jedisCluster.subscribe(jedisPubSub, convertObjectArrayToByteArray_serializeKey(channels));
    } else {
        jedisOperator.subscribe(jedisPubSub, convertObjectArrayToByteArray_serializeKey(channels));
    }
}
 
Example #15
Source File: JedisOperator.java    From smart-cache with Apache License 2.0 5 votes vote down vote up
public void subscribe(final BinaryJedisPubSub jedisPubSub, final byte[]... channels) {
    execute(new JedisExecutor<Void>() {
        @Override
        Void doInJedis(Jedis jedis) {
            jedis.subscribe(jedisPubSub, channels);
            return null;
        }
    });
}
 
Example #16
Source File: JbootCaredisCacheImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
public JbootCaredisCacheImpl() {
    this.caffeineCacheImpl = new CaffeineCacheImpl();
    this.redisCacheImpl = new JbootRedisCacheImpl();
    this.clientId = StrUtil.uuid();
    this.serializer = Jboot.getSerializer();
    this.redis = redisCacheImpl.getRedis();

    this.redis.subscribe(new BinaryJedisPubSub() {
        @Override
        public void onMessage(byte[] channel, byte[] message) {
            JbootCaredisCacheImpl.this.onMessage((String) serializer.deserialize(channel), serializer.deserialize(message));
        }
    }, serializer.serialize(channel));
}
 
Example #17
Source File: JedisPoolFacade.java    From HttpSessionReplacer with MIT License 4 votes vote down vote up
@Override
public void punsubscribe(final RedisPubSub listener, byte[] pattern) {
  ((BinaryJedisPubSub) listener.getLinked()).punsubscribe(pattern);
}
 
Example #18
Source File: JedisClusterFacade.java    From HttpSessionReplacer with MIT License 4 votes vote down vote up
@Override
public void punsubscribe(final RedisPubSub listener, byte[] pattern) {
  ((BinaryJedisPubSub) listener.getLinked()).punsubscribe(pattern);
}
 
Example #19
Source File: CameraNectar.java    From PapARt with GNU Lesser General Public License v3.0 4 votes vote down vote up
public RedisThread(Jedis client, BinaryJedisPubSub listener, String key) {
    this.listener = listener;
    this.key = key;
    this.client = client;
}
 
Example #20
Source File: JedisDummyAdapter.java    From gameserver with Apache License 2.0 4 votes vote down vote up
@Override
public void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels) {
	super.subscribe(jedisPubSub, channels);
}
 
Example #21
Source File: JedisDummyAdapter.java    From gameserver with Apache License 2.0 4 votes vote down vote up
@Override
public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) {
	super.psubscribe(jedisPubSub, patterns);
}
 
Example #22
Source File: JbootLettuceImpl.java    From jboot with Apache License 2.0 2 votes vote down vote up
@Override
public void subscribe(BinaryJedisPubSub binaryListener, byte[]... channels) {

}
 
Example #23
Source File: JbootRedissonImpl.java    From jboot with Apache License 2.0 2 votes vote down vote up
@Override
public void subscribe(BinaryJedisPubSub binaryListener, byte[]... channels) {

}
 
Example #24
Source File: JedisAllCommand.java    From gameserver with Apache License 2.0 2 votes vote down vote up
/**
 * @param jedisPubSub
 * @param channels
 * @see redis.clients.jedis.BinaryJedis#subscribe(redis.clients.jedis.BinaryJedisPubSub,
 *      byte[][])
 */
public abstract void subscribe(BinaryJedisPubSub jedisPubSub,
		byte[]... channels);
 
Example #25
Source File: JedisAllCommand.java    From gameserver with Apache License 2.0 2 votes vote down vote up
/**
 * @param jedisPubSub
 * @param patterns
 * @see redis.clients.jedis.BinaryJedis#psubscribe(redis.clients.jedis.BinaryJedisPubSub,
 *      byte[][])
 */
public abstract void psubscribe(BinaryJedisPubSub jedisPubSub,
		byte[]... patterns);
 
Example #26
Source File: JbootRedis.java    From jboot with Apache License 2.0 2 votes vote down vote up
/**
 * 订阅
 *
 * @param binaryListener
 * @param channels
 */
public void subscribe(BinaryJedisPubSub binaryListener, final byte[]... channels);
 
Example #27
Source File: MultiKeyBinaryCommands.java    From cachecloud with Apache License 2.0 votes vote down vote up
void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels); 
Example #28
Source File: MultiKeyBinaryCommands.java    From cachecloud with Apache License 2.0 votes vote down vote up
void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns); 
Example #29
Source File: MultiKeyBinaryJedisClusterCommands.java    From cachecloud with Apache License 2.0 votes vote down vote up
void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels); 
Example #30
Source File: MultiKeyBinaryJedisClusterCommands.java    From cachecloud with Apache License 2.0 votes vote down vote up
void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns);